Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clang applies constraint checking loosely in variable declaration with concepts #54443

Closed
ldionne opened this issue Mar 18, 2022 · 3 comments
Closed
Labels
accepts-invalid clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts

Comments

@ldionne
Copy link
Member

ldionne commented Mar 18, 2022

The following code compiled with Clang, but not with GCC or MSVC:

template <class T, class U>
struct is_same { static constexpr bool value = false; };

template <class T>
struct is_same<T, T> { static constexpr bool value = true; };

template <class T, class U>
concept same_as = is_same<T, U>::value;

int const& f();

same_as<int const&> auto& i = f();

Both GCC and MSVC complain that the constraint same_as<int const&> is not satisfied, but Clang accepts it. If we change to same_as<int const> auto& i = f();, then GCC and MSVC accept it, and Clang accepts it too, which is really weird!

Godbolt: https://godbolt.org/z/q5K9885vb

@ldionne ldionne added clang:frontend Language frontend issues, e.g. anything involving "Sema" accepts-invalid concepts C++20 concepts labels Mar 18, 2022
@llvmbot
Copy link
Collaborator

llvmbot commented Mar 18, 2022

@llvm/issue-subscribers-clang-frontend

royjacobson added a commit that referenced this issue Mar 23, 2022
Placeholder types were not checked for constraint satisfaction when modified by references or pointers.
The behavior now matches that of GCC and MSVC.

Are there other modifiers we might need to "peel"? I'm not sure my approach to this is the 'right' way to fix this, the loop feels a bit clunky.

GitHub issues [[ #54443 | #54443 ]], [[ #53911 | #53911 ]]

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D122083
@royjacobson
Copy link
Contributor

Fixed https://reviews.llvm.org/D122083

@ldionne
Copy link
Member Author

ldionne commented Mar 24, 2022

Thanks a lot @royjacobson !

mem-frob pushed a commit to draperlaboratory/hope-llvm-project that referenced this issue Oct 7, 2022
Placeholder types were not checked for constraint satisfaction when modified by references or pointers.
The behavior now matches that of GCC and MSVC.

Are there other modifiers we might need to "peel"? I'm not sure my approach to this is the 'right' way to fix this, the loop feels a bit clunky.

GitHub issues [[ llvm/llvm-project#54443 | #54443 ]], [[ llvm/llvm-project#53911 | #53911 ]]

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D122083
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
accepts-invalid clang:frontend Language frontend issues, e.g. anything involving "Sema" concepts C++20 concepts
Projects
Status: No status
Development

No branches or pull requests

3 participants