[PATCH] D132712: [Clang] Fix assert in Sema::LookupTemplateName so that it does not attempt an unconditional cast to TagType
Shafik Yaghmour via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Thu Aug 25 17:35:18 PDT 2022
shafik created this revision.
shafik added reviewers: erichkeane, aaron.ballman.
Herald added a project: All.
shafik requested review of this revision.
In `Sema::LookupTemplateName(...)` seeks to assert that the `ObjectType` is complete or being defined. If the type is incomplete it will attempt to unconditionally cast it to a `TagType` and not all incomplete types are a `TagType`. For example the type could be `void` or it could be an `IncompleteArray`.
This change adds an additional check to confirm it is a `TagType` before attempting to check if it is incomplete or being defined.
https://reviews.llvm.org/D132712
Files:
clang/lib/Sema/SemaTemplate.cpp
clang/test/SemaCXX/member-expr.cpp
Index: clang/test/SemaCXX/member-expr.cpp
===================================================================
--- clang/test/SemaCXX/member-expr.cpp
+++ clang/test/SemaCXX/member-expr.cpp
@@ -228,3 +228,19 @@
.i; // expected-error {{member reference type 'S *' is a pointer; did you mean to use '->'}}
}
}
+
+namespace LookupTemplateNameAssert {
+void f() {}
+
+typedef int at[];
+const at& f2(){}
+
+void g() {
+ f().junk<int>(); // expected-error {{member reference base type 'void' is not a structure or union}}
+// expected-error at -1 {{expected '(' for function-style cast or type construction}}
+// expected-error at -2 {{expected expression}}
+ f2().junk<int>(); // expected-error {{member reference base type 'const at' (aka 'const int[]') is not a structure or union}}
+// expected-error at -1 {{expected '(' for function-style cast or type construction}}
+// expected-error at -2 {{expected expression}}
+}
+}
Index: clang/lib/Sema/SemaTemplate.cpp
===================================================================
--- clang/lib/Sema/SemaTemplate.cpp
+++ clang/lib/Sema/SemaTemplate.cpp
@@ -398,7 +398,7 @@
assert(SS.isEmpty() && "ObjectType and scope specifier cannot coexist");
LookupCtx = computeDeclContext(ObjectType);
IsDependent = !LookupCtx && ObjectType->isDependentType();
- assert((IsDependent || !ObjectType->isIncompleteType() ||
+ assert((IsDependent || !ObjectType->getAs<TagType>() || !ObjectType->isIncompleteType() ||
ObjectType->castAs<TagType>()->isBeingDefined()) &&
"Caller should have completed object type");
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D132712.455768.patch
Type: text/x-patch
Size: 1598 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220826/07bbf09a/attachment.bin>
More information about the cfe-commits
mailing list