Fix PR28366: Handle variables from enclosing local scopes more gracefully during constant expression evaluation.
Only look for a variable's value in the constant expression evaluation activation frame, if the variable was indeed declared in that frame, otherwise it might be a constant expression and be usable within a nested local scope or emit an error.
void f(char c) {
struct X {
static constexpr char f() {
return c; // error gracefully here as opposed to crashing.
}
};
int I = X::f();
}
llvm-svn: 286748
diff --git a/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp b/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
index 526dd27..90a0766 100644
--- a/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
+++ b/clang/test/SemaCXX/cxx1z-constexpr-lambdas.cpp
@@ -46,5 +46,17 @@
} // end ns test_constexpr_call
-#endif // ndef CPP14_AND_EARLIER
+namespace test_captureless_lambda {
+void f() {
+ const char c = 'c';
+ auto L = [] { return c; };
+ constexpr char C = L();
+}
+
+void f(char c) { //expected-note{{declared here}}
+ auto L = [] { return c; }; //expected-error{{cannot be implicitly captured}} expected-note{{lambda expression begins here}}
+ int I = L();
+}
+}
+#endif // ndef CPP14_AND_EARLIER