[cfe-commits] r82159 - in /cfe/trunk: lib/Sema/SemaDecl.cpp lib/Sema/SemaDeclCXX.cpp test/SemaTemplate/default-expr-arguments.cpp
Douglas Gregor
dgregor at apple.com
Thu Sep 17 12:51:30 PDT 2009
Author: dgregor
Date: Thu Sep 17 14:51:30 2009
New Revision: 82159
URL: http://llvm.org/viewvc/llvm-project?rev=82159&view=rev
Log:
Merge uninstantiated default arguments more carefully, and try not to
complain about specializations of member functions that are not
definitions. Fixes PR4995.
Modified:
cfe/trunk/lib/Sema/SemaDecl.cpp
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp
Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=82159&r1=82158&r2=82159&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDecl.cpp Thu Sep 17 14:51:30 2009
@@ -2684,7 +2684,9 @@
if (D.getCXXScopeSpec().isSet() && !NewFD->isInvalidDecl()) {
// An out-of-line member function declaration must also be a
// definition (C++ [dcl.meaning]p1).
- if (!IsFunctionDefinition && !isFriend) {
+ // FIXME: Find a better way to recognize out-of-line specializations!
+ if (!IsFunctionDefinition && !isFriend &&
+ !(TemplateParamLists.size() && !FunctionTemplate)) {
Diag(NewFD->getLocation(), diag::err_out_of_line_declaration)
<< D.getCXXScopeSpec().getRange();
NewFD->setInvalidDecl();
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=82159&r1=82158&r2=82159&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Thu Sep 17 14:51:30 2009
@@ -280,9 +280,13 @@
Diag(OldParam->getLocation(), diag::note_previous_definition)
<< OldParam->getDefaultArgRange();
Invalid = true;
- } else if (OldParam->getDefaultArg()) {
+ } else if (OldParam->hasDefaultArg()) {
// Merge the old default argument into the new parameter
- NewParam->setDefaultArg(OldParam->getDefaultArg());
+ if (OldParam->hasUninstantiatedDefaultArg())
+ NewParam->setUninstantiatedDefaultArg(
+ OldParam->getUninstantiatedDefaultArg());
+ else
+ NewParam->setDefaultArg(OldParam->getDefaultArg());
} else if (NewParam->hasDefaultArg()) {
if (New->getDescribedFunctionTemplate()) {
// Paragraph 4, quoted above, only applies to non-template functions.
Modified: cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp?rev=82159&r1=82158&r2=82159&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp (original)
+++ cfe/trunk/test/SemaTemplate/default-expr-arguments.cpp Thu Sep 17 14:51:30 2009
@@ -1,5 +1,11 @@
// RUN: clang-cc -fsyntax-only -verify %s
+template<typename T>
+class C { C(int a0 = 0); };
+
+template<>
+C<char>::C(int a0);
+
struct S { };
template<typename T> void f1(T a, T b = 10) { } // expected-error{{cannot initialize 'b' with an rvalue of type 'int'}}
More information about the cfe-commits
mailing list