4

I made a concept that checks the type of a data member:

#include <concepts>
#include <iostream>

template < typename DataType >
struct StaticA
{
private:
    static DataType value;
};

template < typename DataType >
struct NonStaticA
{
private:
    DataType value;
};

template < typename DataType >
struct B
{
    DataType value;
};

template < typename Class >
concept Concept = std::same_as < decltype(Class::value), int >;

int main()
{
    std::cout << Concept < StaticA < int > > << "\n"; // Prints 0
    std::cout << Concept < NonStaticA < int > > << "\n"; // Prints 0 or 1, depending on the compiler.
    std::cout << Concept < B < int > > << "\n"; // Prints 1

    return 0;
}

In this case, the second print should also be 0 on MSVC, just like it happens on gcc, right?

I believe that's the case, because of this answer: C++ concept with friend-like access

You may check the aforementioned code here: https://godbolt.org/z/9afcEes7x

Thanks for your attention!

Jean Amaro
  • 315
  • 1
  • 7
  • 2
    I would say msvc bug, adding `decltype(NonStaticA::value) b = 42;` fails to compile as expected [Demo](https://godbolt.org/z/n3nenqhfW). – Jarod42 Sep 21 '22 at 07:32

1 Answers1

1

It seems that this issue was indeed a bug: https://developercommunity.visualstudio.com/t/C-concepts-are-able-to-access-private-/10155281

The fix shall be released in the future.

Jean Amaro
  • 315
  • 1
  • 7