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

Improper resolution of constraint requirements when using CRTP #47418

Closed
llvmbot opened this issue Nov 4, 2020 · 2 comments
Closed

Improper resolution of constraint requirements when using CRTP #47418

llvmbot opened this issue Nov 4, 2020 · 2 comments
Labels
bugzilla Issues migrated from bugzilla c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate

Comments

@llvmbot
Copy link
Member

llvmbot commented Nov 4, 2020

Bugzilla Link 48074
Version 11.0
OS Windows NT
Reporter LLVM Bugzilla Contributor
CC @ldalessa,@zygoloid,@jwakely

Extended Description

Using libstdc++'s header with clang 11 doesn't compile even the most basic examples:

#include
auto w = std::views::iota(0);

The failure reduces to the following:

template T declval();

template using begin_t = decltype(declval<T&>().begin());
template concept C = true;

template
struct simple_view_interface
{
auto also_begin() requires
#ifdef TYPE_TRAIT
C<begin_t>
#else
requires (D d) { {d.begin()} -> C; }
#endif
{
return static_cast<D&>(*this).begin();
}
};

struct wat_view : simple_view_interface<wat_view>
{
auto begin() -> int* { return nullptr; }
};

auto w = wat_view().also_begin();

Both spellings of the requirement on also_begin() should be equivalent, and should be valid in this case. The checking of the requirements should be deferred until instantiation, at which point, wat_view is complete.

If TYPE_TRAIT is defined, the requirement is eagerly instantiated, an even the definition of wat_view fails to compile:

:3:62: error: no member named 'begin' in 'wat_view' template using begin_t = decltype(declval().begin()); ~~~~~~~~~~~~~ ^ :11:11: note: in instantiation of template type alias 'begin_t' requested here C> ^ :20:19: note: in instantiation of template class 'simple_view_interface' requested here struct wat_view : simple_view_interface ^

If TYPE_TRAIT is not defined, wat_view is properly defined, but usage fails:

:25:21: error: invalid reference to function 'also_begin': constraints not satisfied auto w = wat_view().also_begin(); ^ :13:29: note: because 'd.begin()' would be invalid: no member named 'begin' in 'wat_view' requires (D d) { {d.begin()} -> C; } ^

Even though there is a member named 'begin' in 'wat_view'.

The program should be valid either way. gcc accepts both.

@llvmbot llvmbot transferred this issue from llvm/llvm-bugzilla-archive Dec 10, 2021
@royjacobson
Copy link
Contributor

Confirmed to work after https://reviews.llvm.org/D126907, so duplicate of #44178. Closing.

@royjacobson royjacobson closed this as not planned Won't fix, can't repro, duplicate, stale Sep 23, 2022
@royjacobson royjacobson moved this to Done in C++ 20 in Clang Sep 23, 2022
@royjacobson royjacobson added the duplicate Resolved as duplicate label Sep 23, 2022
@EugeneZelenko EugeneZelenko added the clang:frontend Language frontend issues, e.g. anything involving "Sema" label Sep 23, 2022
@llvmbot
Copy link
Member Author

llvmbot commented Sep 23, 2022

@llvm/issue-subscribers-clang-frontend

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugzilla Issues migrated from bugzilla c++20 clang:frontend Language frontend issues, e.g. anything involving "Sema" duplicate Resolved as duplicate
Projects
Status: Done
Development

No branches or pull requests

3 participants