[cfe-commits] r129240 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp test/SemaCXX/MicrosoftExtensions.cpp
Francois Pichet
pichet2000 at gmail.com
Sat Apr 9 20:03:52 PDT 2011
Author: fpichet
Date: Sat Apr 9 22:03:52 2011
New Revision: 129240
URL: http://llvm.org/viewvc/llvm-project?rev=129240&view=rev
Log:
MSVC accepts that default parameters be redefined for member functions
of template class. The new value is ignored.
This fixes 1 error when parsing MSVC 2010 header files with clang.
Modified:
cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
cfe/trunk/lib/Sema/SemaDeclCXX.cpp
cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=129240&r1=129239&r2=129240&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Sat Apr 9 22:03:52 2011
@@ -1301,6 +1301,8 @@
"C does not support default arguments">;
def err_param_default_argument_redefinition : Error<
"redefinition of default argument">;
+def war_param_default_argument_redefinition : ExtWarn<
+ "redefinition of default argument">;
def err_param_default_argument_missing : Error<
"missing default argument on parameter">;
def err_param_default_argument_missing_name : Error<
Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=129240&r1=129239&r2=129240&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Sat Apr 9 22:03:52 2011
@@ -293,12 +293,24 @@
// for NewParam to find the last source location in the type... but it
// isn't worth the effort right now. This is the kind of test case that
// is hard to get right:
+ unsigned DiagDefaultParamID =
+ diag::err_param_default_argument_redefinition;
+
+ // MSVC accepts that default parameters be redefined for member functions
+ // of template class. The new default parameter's value is ignored.
+ Invalid = true;
+ if (getLangOptions().Microsoft) {
+ CXXMethodDecl* MD = dyn_cast<CXXMethodDecl>(New);
+ if (MD && MD->getParent()->getDescribedClassTemplate()) {
+ DiagDefaultParamID = diag::war_param_default_argument_redefinition;
+ Invalid = false;
+ }
+ }
// int f(int);
// void g(int (*fp)(int) = f);
// void g(int (*fp)(int) = &f);
- Diag(NewParam->getLocation(),
- diag::err_param_default_argument_redefinition)
+ Diag(NewParam->getLocation(), DiagDefaultParamID)
<< NewParam->getDefaultArgRange();
// Look for the function declaration where the default argument was
@@ -313,7 +325,6 @@
Diag(OldParam->getLocation(), diag::note_previous_definition)
<< OldParam->getDefaultArgRange();
- Invalid = true;
} else if (OldParam->hasDefaultArg()) {
// Merge the old default argument into the new parameter.
// It's important to use getInit() here; getDefaultArg()
Modified: cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp?rev=129240&r1=129239&r2=129240&view=diff
==============================================================================
--- cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp (original)
+++ cfe/trunk/test/SemaCXX/MicrosoftExtensions.cpp Sat Apr 9 22:03:52 2011
@@ -127,3 +127,12 @@
+template <class T>
+class BB {
+public:
+ void f(int g = 10 ); // expected-note {{previous definition is here}}
+};
+
+template <class T>
+void BB<T>::f(int g = 0) { } // expected-warning {{redefinition of default argument}}
+
More information about the cfe-commits
mailing list