-
Notifications
You must be signed in to change notification settings - Fork 14.5k
[Clang] prevent recovery call expression from proceeding with explicit attributes and undeclared templates #107786
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
Conversation
@llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) ChangesFixes #107047 Full diff: https://github.com/llvm/llvm-project/pull/107786.diff 3 Files Affected:
diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index f7c3194c91fa31..f96045c57e7a0d 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -376,8 +376,9 @@ Bug Fixes to C++ Support
- Fixed a bug in the substitution of empty pack indexing types. (#GH105903)
- Clang no longer tries to capture non-odr used default arguments of template parameters of generic lambdas (#GH107048)
- Fixed a bug where defaulted comparison operators would remove ``const`` from base classes. (#GH102588)
-
- Fix a crash when using ``source_location`` in the trailing return type of a lambda expression. (#GH67134)
+- Fixed an assertion failure when invoking recovery call expressions with explicit attributes
+ and undeclared templates. (#GH107047, #GH49093)
Bug Fixes to AST Handling
^^^^^^^^^^^^^^^^^^^^^^^^^
diff --git a/clang/lib/Sema/SemaTemplate.cpp b/clang/lib/Sema/SemaTemplate.cpp
index 513f83146fb59e..1ec6219bbd6ea8 100644
--- a/clang/lib/Sema/SemaTemplate.cpp
+++ b/clang/lib/Sema/SemaTemplate.cpp
@@ -4458,6 +4458,12 @@ ExprResult Sema::BuildTemplateIdExpr(const CXXScopeSpec &SS,
R.getAsSingle<ConceptDecl>(), TemplateArgs);
}
+ if (TemplateArgs && R.getAsSingle<FunctionDecl>()) {
+ if (R.getAsSingle<FunctionDecl>()->getTemplateSpecializationKind() ==
+ TemplateSpecializationKind::TSK_Undeclared)
+ return ExprError();
+ }
+
// We don't want lookup warnings at this point.
R.suppressDiagnostics();
diff --git a/clang/test/SemaTemplate/recovery-crash-cxx20.cpp b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp
new file mode 100644
index 00000000000000..dd92ddcd36ab02
--- /dev/null
+++ b/clang/test/SemaTemplate/recovery-crash-cxx20.cpp
@@ -0,0 +1,32 @@
+// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s
+
+namespace GH49093 {
+ class B {
+ public:
+ static int a() { return 0; } // expected-note {{member is declared here}}
+ decltype(a< 0 >(0)) test; // expected-error {{member 'a' used before its declaration}}
+ };
+
+ struct C {
+ static int a() { return 0; } // expected-note {{member is declared here}}
+ decltype(a < 0 > (0)) test; // expected-error {{member 'a' used before its declaration}}
+ };
+
+ void test_is_bool(bool t) {}
+ void test_is_bool(int t) {}
+
+ int main() {
+ B b;
+ test_is_bool(b.test);
+
+ C c;
+ test_is_bool(c.test);
+ }
+}
+
+namespace GH107047 {
+ struct A {
+ static constexpr auto test() { return 1; } // expected-note {{member is declared here}}
+ static constexpr int s = test< 1 >(); // expected-error {{member 'test' used before its declaration}}
+ };
+}
|
ae9b6f6
to
8774b4b
Compare
7eb20a4
to
19e6556
Compare
…t attributes and undeclared templates
9b1b040
to
e9948a1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Diag seems reasonable to me now. I want Aaron to take another look (he's sadly out this week, so it'll have to be when he gets back), but I think this seems to make sense here.
@erichkeane thanks for the feedback |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. do you need me to merge it for you?
@cor3ntin yes, I do. Thanks |
…t attributes and undeclared templates (llvm#107786) Fixes llvm#107047 Fixes llvm#49093
Fixes #107047
Fixes #49093