[clang] [clang][ExprConst] Explicitly reject dependent types without diagnostic (PR #108598)
Timm Baeder via cfe-commits
cfe-commits at lists.llvm.org
Fri Sep 13 09:13:45 PDT 2024
https://github.com/tbaederr created https://github.com/llvm/llvm-project/pull/108598
This should never happen I believe, but if it does, the "non-literal type '<dependent type>'" diagnostic is weird.
That dependent type should never reach this stage I believe.
If we actually try to generate code for this, we hit an assertion in codegen: https://godbolt.org/z/b19P9eqf9
>From 6524f669c7ecda5d49d01c036b233de7f8722cbe Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Timm=20B=C3=A4der?= <tbaeder at redhat.com>
Date: Fri, 13 Sep 2024 18:11:46 +0200
Subject: [PATCH] [clang][ExprConst] Explicitly reject dependent types without
diagnostic
This should never happen I believe, but if it does, the
"non-literal type '<dependent type>'" diagnostic is weird.
---
clang/lib/AST/ExprConstant.cpp | 2 ++
clang/test/SemaCXX/cxx2a-template-lambdas.cpp | 4 +---
2 files changed, 3 insertions(+), 3 deletions(-)
diff --git a/clang/lib/AST/ExprConstant.cpp b/clang/lib/AST/ExprConstant.cpp
index 6387e375dda79c..b98904ea3a2bbd 100644
--- a/clang/lib/AST/ExprConstant.cpp
+++ b/clang/lib/AST/ExprConstant.cpp
@@ -16009,6 +16009,8 @@ static bool Evaluate(APValue &Result, EvalInfo &Info, const Expr *E) {
if (!EvaluateAtomic(E, nullptr, Result, Info))
return false;
}
+ } else if (T->isDependentType()) {
+ return false;
} else if (Info.getLangOpts().CPlusPlus11) {
Info.FFDiag(E, diag::note_constexpr_nonliteral) << E->getType();
return false;
diff --git a/clang/test/SemaCXX/cxx2a-template-lambdas.cpp b/clang/test/SemaCXX/cxx2a-template-lambdas.cpp
index 00ba291fbd1981..8a7191f76c3e1d 100644
--- a/clang/test/SemaCXX/cxx2a-template-lambdas.cpp
+++ b/clang/test/SemaCXX/cxx2a-template-lambdas.cpp
@@ -43,13 +43,11 @@ struct ShadowMe {
#if __cplusplus >= 201102L
template<typename T>
constexpr T outer() {
- // FIXME: The C++11 error seems wrong
return []<T x>() { return x; }.template operator()<123>(); // expected-error {{no matching member function}} \
expected-note {{candidate template ignored}} \
- cxx11-note {{non-literal type '<dependent type>' cannot be used in a constant expression}} \
cxx14-note {{non-literal type}}
}
-static_assert(outer<int>() == 123); // cxx11-cxx14-error {{not an integral constant expression}} cxx11-cxx14-note {{in call}}
+static_assert(outer<int>() == 123); // cxx11-cxx14-error {{not an integral constant expression}} cxx14-note {{in call}}
template int *outer<int *>(); // expected-note {{in instantiation}}
#endif
More information about the cfe-commits
mailing list