[clang] [Clang] Treat default template argument as constant expressions (PR #107073)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Sep 4 00:22:14 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}}
----------------
cor3ntin wrote:
All of these work (because they are not local entities so don't need capturing https://eel.is/c++draft/basic#pre-7)
https://github.com/llvm/llvm-project/pull/107073
More information about the cfe-commits
mailing list