[clang] e562a40 - Fix for PR47544. Clang is crashing after generating the right
Zahira Ammarguellat via cfe-commits
cfe-commits at lists.llvm.org
Tue Oct 27 06:07:38 PDT 2020
Author: Zahira Ammarguellat
Date: 2020-10-27T05:57:39-07:00
New Revision: e562a40871da14cef6685efef09760bca2718269
URL: https://github.com/llvm/llvm-project/commit/e562a40871da14cef6685efef09760bca2718269
DIFF: https://github.com/llvm/llvm-project/commit/e562a40871da14cef6685efef09760bca2718269.diff
LOG: Fix for PR47544. Clang is crashing after generating the right
diagnostic for a re-declaration of a friend method.d
https://reviews.llvm.org/D88112
Added:
clang/test/SemaCXX/invalid-decl.cpp
Modified:
clang/lib/Parse/ParseCXXInlineMethods.cpp
Removed:
################################################################################
diff --git a/clang/lib/Parse/ParseCXXInlineMethods.cpp b/clang/lib/Parse/ParseCXXInlineMethods.cpp
index d05332b5ac5a..12941f214cbc 100644
--- a/clang/lib/Parse/ParseCXXInlineMethods.cpp
+++ b/clang/lib/Parse/ParseCXXInlineMethods.cpp
@@ -405,14 +405,21 @@ void Parser::ParseLexedMethodDeclaration(LateParsedMethodDeclaration &LM) {
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());
+ }
}
}
diff --git a/clang/test/SemaCXX/invalid-decl.cpp b/clang/test/SemaCXX/invalid-decl.cpp
new file mode 100644
index 000000000000..0cb8b00a8d12
--- /dev/null
+++ b/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}}
+};
More information about the cfe-commits
mailing list