aboutsummaryrefslogtreecommitdiff
path: root/clang/lib/Sema/Sema.cpp
diff options
context:
space:
mode:
authorAaron Ballman <aaron@aaronballman.com>2022-03-08 10:09:16 -0500
committerAaron Ballman <aaron@aaronballman.com>2022-03-08 10:19:15 -0500
commit1c55f05c6a6b58f8cc7b15a37e79753fb8abe3e3 (patch)
tree6edcd3b1970225ff83322d21f2a71d800e31538d /clang/lib/Sema/Sema.cpp
parent5b7941ad7c893b4bb019e3c96b760b0f2670ccfc (diff)
downloadllvm-1c55f05c6a6b58f8cc7b15a37e79753fb8abe3e3.zip
llvm-1c55f05c6a6b58f8cc7b15a37e79753fb8abe3e3.tar.gz
llvm-1c55f05c6a6b58f8cc7b15a37e79753fb8abe3e3.tar.bz2
Properly diagnose constant evaluation issues at TU scope
We were not creating an evaluation context for the TU scope, so we never popped an evaluation context for it. Popping the evaluation context triggers a number of diagnostics, including warnings about immediate invocations that we were previously missing. Note: I think we have an additional issue that we should solve, but not as part of this patch. I don't think Clang is properly modeling static initialization as happening before constant expression evaluation. I think structure members members are zero initialized per http://eel.is/c++draft/basic.start.static#1, https://eel.is/c++draft/basic.start.static#2.sentence-2, and http://eel.is/c++draft/dcl.init#general-6.2 and the new test case actually should be accepted. However, it's also worth noting that other compilers behave the way this patch makes Clang behave: https://godbolt.org/z/T7noqhdPr
Diffstat (limited to 'clang/lib/Sema/Sema.cpp')
-rw-r--r--clang/lib/Sema/Sema.cpp3
1 files changed, 3 insertions, 0 deletions
diff --git a/clang/lib/Sema/Sema.cpp b/clang/lib/Sema/Sema.cpp
index f1dc02d..ed868a9 100644
--- a/clang/lib/Sema/Sema.cpp
+++ b/clang/lib/Sema/Sema.cpp
@@ -233,6 +233,9 @@ Sema::Sema(Preprocessor &pp, ASTContext &ctxt, ASTConsumer &consumer,
// Tell diagnostics how to render things from the AST library.
Diags.SetArgToStringFn(&FormatASTNodeDiagnosticArgument, &Context);
+ // This evaluation context exists to ensure that there's always at least one
+ // valid evaluation context available. It is never removed from the
+ // evaluation stack.
ExprEvalContexts.emplace_back(
ExpressionEvaluationContext::PotentiallyEvaluated, 0, CleanupInfo{},
nullptr, ExpressionEvaluationContextRecord::EK_Other);