[cfe-commits] r129240 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp test/SemaCXX/MicrosoftExtensions.cpp

Eli Friedman eli.friedman at gmail.com
Sat Apr 9 20:43:22 PDT 2011


On Sat, Apr 9, 2011 at 8:03 PM, Francois Pichet <pichet2000 at gmail.com> wrote:
> 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);

1. You're splitting a comment which should be a single unit here.

2. The default argument for NewParam isn't getting set correctly; look
at what happens in the non-error case.

-Eli

> -      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}}
> +
>
>
> _______________________________________________
> cfe-commits mailing list
> cfe-commits at cs.uiuc.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits
>




More information about the cfe-commits mailing list