[clang] [Clang] Treat default template argument as constant expressions (PR #107073)
Shafik Yaghmour via cfe-commits
cfe-commits at lists.llvm.org
Tue Sep 3 17:34:42 PDT 2024
================
@@ -97,3 +97,29 @@ void foo() {
}
#endif
+
+#if __cplusplus >= 202002L
+void GH107048() {
+ constexpr int x{};
+ const int y{};
+ auto b = []<int=x, int=y>{};
+ using A = decltype([]<int=x>{});
+
+ int z; // expected-note {{'z' declared here}}
+ auto c = []<int t=z>{
+ // expected-error at -1 {{no matching function for call to object of type}} \
+ // expected-error at -1 {{variable 'z' cannot be implicitly captured in a lambda with no capture-default specified}} \
+ // expected-note at -1 {{lambda expression begins here}} \
+ // expected-note at -1 4{{capture}} \
+ // expected-note at -1 {{candidate template ignored: substitution failure: reference to local variable 'z' declared in enclosing function}}
+ return t;
+ }();
+
+ struct S {};
+ constexpr S s; // expected-note {{'s' declared here}}
+ auto class_type = []<S=s>{};
+ // expected-error at -1 {{variable 's' cannot be implicitly captured in a lambda with no capture-default specified}} \
+ // expected-note at -1 {{lambda expression begins here}} \
+ // expected-note at -1 4{{capture}}
----------------
shafik wrote:
Curious about these cases: https://godbolt.org/z/xWbWYfnf3
```cpp
struct S {};
constexpr S s;
void f() {
auto class_type = []<S=s>{};
}
void h() {
static constexpr S s;
auto class_type = []<S=s>{};
}
template <S=s>
void g() {}
```
https://github.com/llvm/llvm-project/pull/107073
More information about the cfe-commits
mailing list