[PATCH] D115248: [clang] Fix Bug 28101
PoYao Chang via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 7 06:11:48 PST 2021
rZhBoYao created this revision.
rZhBoYao added reviewers: rsmith, aaron.ballman, erichkeane, v.g.vassilev, rnk.
rZhBoYao added a project: clang.
rZhBoYao requested review of this revision.
Herald added a subscriber: cfe-commits.
This should fix Bug 28101 <https://bugs.llvm.org/show_bug.cgi?id=28101> where the culprit line is parsed as `FieldDecl 0x2136240 <line:6:3, col:16> col:6 'T':'T'`(why not `A<T>` tho?).
I observed that GCC(trunk on godbolt.org) would issue: `<source>:6:6: error: field 'int A<int>::A' with same name as class`, which corresponds to clang's `diag::err_member_name_of_class`. But as the dumped AST shows, there is no name on the FieldDecl, and then I found clang would issue `diag::err_expected_member_name_or_semi` on `int (double) {};`, which resembles `T (A < T >) {};` so I went with this error.
I am ready to be corrected as I'm new to clang and this differs from GCC's behavior. Any guidance and comments would be appreciated.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D115248
Files:
clang/lib/Parse/ParseDecl.cpp
clang/lib/Sema/SemaDeclCXX.cpp
Index: clang/lib/Sema/SemaDeclCXX.cpp
===================================================================
--- clang/lib/Sema/SemaDeclCXX.cpp
+++ clang/lib/Sema/SemaDeclCXX.cpp
@@ -15440,6 +15440,11 @@
break;
}
}
+ if (LLVM_UNLIKELY(!Pattern))
+ for (const auto *FD : ClassPattern->fields())
+ if (Diags.hasErrorOccurred() && !FD->getIdentifier()) {
+ return ExprError();
+ }
assert(Pattern && "We must have set the Pattern!");
if (!Pattern->hasInClassInitializer() ||
Index: clang/lib/Parse/ParseDecl.cpp
===================================================================
--- clang/lib/Parse/ParseDecl.cpp
+++ clang/lib/Parse/ParseDecl.cpp
@@ -6205,6 +6205,11 @@
// is exited (and the declarator has been parsed).
DeclScopeObj.EnterDeclaratorScope();
}
+ if (D.hasName() && !D.getIdentifier())
+ Diag(getMissingDeclaratorIdLoc(D, Tok.getLocation()),
+ diag::err_expected_member_name_or_semi)
+ << (D.getDeclSpec().isEmpty() ? SourceRange()
+ : D.getDeclSpec().getSourceRange());
} else if (D.mayOmitIdentifier()) {
// This could be something simple like "int" (in which case the declarator
// portion is empty), if an abstract-declarator is allowed.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115248.392369.patch
Type: text/x-patch
Size: 1317 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211207/7d4cdde0/attachment.bin>
More information about the cfe-commits
mailing list