-
Notifications
You must be signed in to change notification settings - Fork 12.2k
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
Compiler error for requires expression with templated base class member function #84020
Comments
@llvm/issue-subscribers-clang-frontend Author: Alex_Mueller (rath3t)
The following code fails to compile with clang trunk and clang 16 (See godbolt link).
The templated member function is not found by clang and therefore the `static_assert` is triggered.
The struct struct B {
template <typename S>
void foo();
void bar();
};
template <typename T, typename S>
struct A : T {
auto foo() {
static_assert(requires { T::template foo<S>(); }); // fails with clang
static_assert(requires { T::bar(); }); // works with clang and gcc 12.2
}
};
int main() {
A<B, double> a;
a.foo();
} |
@llvm/issue-subscribers-c-20 Author: Alex_Mueller (rath3t)
The following code fails to compile with clang trunk and clang 16 (See godbolt link).
The templated member function is not found by clang and therefore the `static_assert` is triggered.
The struct struct B {
template <typename S>
void foo();
void bar();
};
template <typename T, typename S>
struct A : T {
auto foo() {
static_assert(requires { T::template foo<S>(); }); // fails with clang
static_assert(requires { T::bar(); }); // works with clang and gcc 12.2
}
};
int main() {
A<B, double> a;
a.foo();
} |
EDG reject both but MSVC accepts both: https://godbolt.org/z/7G8rPY9hz I don't see why they should be rejected but not totally sure. |
I don't have a good idea, but both lookups seem to me like they should work. |
At a glance, this looks like it’s a duplicate of #83979? |
Ah yes somebody copied my stackoverflow post https://stackoverflow.com/questions/78106241/compiler-divergence-in-delayed-template-instantiation. |
@shafik I agree with Erich, both lookup should work. |
In the future it is helpful to link to Stackoverflow bugs, especially if someone on the committee already analyzed the bug then that makes screening a lot faster and we can get to more bugs. |
I will add the stack overflow link in the future thanks! Sorry for the confusion. For my defense though, the answer on stackoverflow came after I posted here. |
It is also helpful for discoverability, if someone else has referenced that bug we can tie those bugs together quickly. Same reason to include assertions and backtraces in bug reports. |
…ass member function (#85198) Fix #84020 Skip checking implicit object parameter in the context of `RequiresExprBodyDecl`. Co-authored-by: huqizhi <[email protected]>
…solvedCallExpr() after fd87d76 (#111277) The special-casing for RequiresExprBodyDecl caused a regression, as reported in #110785. The original fix for #84020 has been superseded by fd87d76, which establishes a `DependentScopeDeclRefExpr` instead of a `CXXDependentScopeMemberExpr` for the case in issue. So the spurious diagnostic in #84020 would no longer occur. This also merges the test for #84020 together with that for #110785 into clang/test/SemaTemplate/instantiate-requires-expr.cpp. No release note because I think this merits a backport. Fixes #110785
…solvedCallExpr() after fd87d76 (llvm#111277) The special-casing for RequiresExprBodyDecl caused a regression, as reported in llvm#110785. The original fix for llvm#84020 has been superseded by fd87d76, which establishes a `DependentScopeDeclRefExpr` instead of a `CXXDependentScopeMemberExpr` for the case in issue. So the spurious diagnostic in llvm#84020 would no longer occur. This also merges the test for llvm#84020 together with that for llvm#110785 into clang/test/SemaTemplate/instantiate-requires-expr.cpp. No release note because I think this merits a backport. Fixes llvm#110785 (cherry picked from commit 8c15470)
…solvedCallExpr() after fd87d76 (llvm#111277) The special-casing for RequiresExprBodyDecl caused a regression, as reported in llvm#110785. The original fix for llvm#84020 has been superseded by fd87d76, which establishes a `DependentScopeDeclRefExpr` instead of a `CXXDependentScopeMemberExpr` for the case in issue. So the spurious diagnostic in llvm#84020 would no longer occur. This also merges the test for llvm#84020 together with that for llvm#110785 into clang/test/SemaTemplate/instantiate-requires-expr.cpp. No release note because I think this merits a backport. Fixes llvm#110785 (cherry picked from commit 8c15470)
The following code fails to compile with clang trunk and clang 16 (See godbolt link).
The templated member function is not found by clang and therefore the
static_assert
is triggered.The struct
A
inherits fromT
and therefore the base class member functionfoo
exists, thus thestatic_assert
should not trigger.It works for non-templated base class member functions though.
Godbolt
The text was updated successfully, but these errors were encountered: