[PATCH] D90165: Clang is crashing after generating the right diagnostic fora re-declaration of a friend method - Fix for PR47544.
Zahira Ammarguellat via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 26 08:47:20 PDT 2020
zahiraam created this revision.
Herald added a project: clang.
Herald added a subscriber: cfe-commits.
zahiraam requested review of this revision.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D90165
Files:
clang/lib/Parse/ParseCXXInlineMethods.cpp
clang/test/SemaCXX/invalid-decl.cpp
Index: clang/test/SemaCXX/invalid-decl.cpp
===================================================================
--- /dev/null
+++ clang/test/SemaCXX/invalid-decl.cpp
@@ -0,0 +1,11 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+class test1 {
+ template<typename> friend int bar(bool = true) {} // expected-note {{previous declaration is here}}
+ template<typename> friend int bar(bool); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
+};
+
+class test2 {
+ friend int bar(bool = true) {} // expected-note {{previous declaration is here}}
+ friend int bar(bool); // expected-error{{friend declaration specifying a default argument must be the only declaration}}
+};
Index: clang/lib/Parse/ParseCXXInlineMethods.cpp
===================================================================
--- clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -405,14 +405,22 @@
ConsumeAnyToken();
} else if (HasUnparsed) {
assert(Param->hasInheritedDefaultArg());
- FunctionDecl *Old = cast<FunctionDecl>(LM.Method)->getPreviousDecl();
- ParmVarDecl *OldParam = Old->getParamDecl(I);
- assert (!OldParam->hasUnparsedDefaultArg());
- if (OldParam->hasUninstantiatedDefaultArg())
- Param->setUninstantiatedDefaultArg(
- OldParam->getUninstantiatedDefaultArg());
+ const FunctionDecl *Old;
+ if (const auto *FunTmpl =
+ dyn_cast<FunctionTemplateDecl>(LM.Method))
+ Old =
+ cast<FunctionDecl>(FunTmpl->getTemplatedDecl())->getPreviousDecl();
else
- Param->setDefaultArg(OldParam->getInit());
+ Old = cast<FunctionDecl>(LM.Method)->getPreviousDecl();
+ if (Old) {
+ ParmVarDecl *OldParam = const_cast<ParmVarDecl*>(Old->getParamDecl(I));
+ assert(!OldParam->hasUnparsedDefaultArg());
+ if (OldParam->hasUninstantiatedDefaultArg())
+ Param->setUninstantiatedDefaultArg(
+ OldParam->getUninstantiatedDefaultArg());
+ else
+ Param->setDefaultArg(OldParam->getInit());
+ }
}
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D90165.300689.patch
Type: text/x-patch
Size: 2145 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20201026/4dbc0168/attachment.bin>
More information about the cfe-commits
mailing list