Skip to content

[clang][ExprConst] Explicitly reject dependent types without diagnostic #108598

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from

Conversation

tbaederr
Copy link
Contributor

@tbaederr tbaederr commented Sep 13, 2024

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

This should never happen I believe, but if it does, the
"non-literal type '<dependent type>'" diagnostic is weird.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Sep 13, 2024
@llvmbot
Copy link
Member

llvmbot commented Sep 13, 2024

@llvm/pr-subscribers-clang

Author: Timm Baeder (tbaederr)

Changes

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


Full diff: https://github.com/llvm/llvm-project/pull/108598.diff

2 Files Affected:

  • (modified) clang/lib/AST/ExprConstant.cpp (+2)
  • (modified) clang/test/SemaCXX/cxx2a-template-lambdas.cpp (+1-3)
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
 

@tbaederr
Copy link
Contributor Author

Ping

@cor3ntin
Copy link
Contributor

I don't think there is much value in changing the status quo here.
There is evidently a bug somewhere before that code that we should find instead (and then we can replace the existing code by an assert)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants