[cfe-commits] r146480 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDecl.cpp test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp

Douglas Gregor dgregor at apple.com
Wed Dec 14 07:58:07 PST 2011


On Dec 13, 2011, at 12:03 AM, David Blaikie wrote:

> Author: dblaikie
> Date: Tue Dec 13 02:03:36 2011
> New Revision: 146480
> 
> URL: http://llvm.org/viewvc/llvm-project?rev=146480&view=rev
> Log:
> Disallow decltype in qualified declarator-ids.
> 
> Added:
>    cfe/trunk/test/CXX/dcl.decl/dcl.meaning/p1-0x.cpp
> Modified:
>    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
>    cfe/trunk/lib/Sema/SemaDecl.cpp
>    cfe/trunk/test/CXX/expr/expr.prim/expr.prim.general/p8-0x.cpp
> 
> Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=146480&r1=146479&r2=146480&view=diff
> ==============================================================================
> --- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
> +++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Dec 13 02:03:36 2011
> @@ -1144,6 +1144,8 @@
> def warn_cxx98_compat_decltype : Warning<
>   "'decltype' type specifier is incompatible with C++98">,
>   InGroup<CXX98Compat>, DefaultIgnore;
> +def err_decltype_in_declarator : Error<
> +    "'decltype' cannot be used to name a declaration">;
> 
> // C++11 auto
> def warn_cxx98_compat_auto_type_specifier : Warning<
> 
> Modified: cfe/trunk/lib/Sema/SemaDecl.cpp
> URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDecl.cpp?rev=146480&r1=146479&r2=146480&view=diff
> ==============================================================================
> --- cfe/trunk/lib/Sema/SemaDecl.cpp (original)
> +++ cfe/trunk/lib/Sema/SemaDecl.cpp Tue Dec 13 02:03:36 2011
> @@ -3203,6 +3203,16 @@
>          (S->getFlags() & Scope::TemplateParamScope) != 0)
>     S = S->getParent();
> 
> +  if (NestedNameSpecifierLoc SpecLoc = 
> +        D.getCXXScopeSpec().getWithLocInContext(Context)) {
> +    while (SpecLoc.getPrefix())
> +      SpecLoc = SpecLoc.getPrefix();
> +    if (dyn_cast_or_null<DecltypeType>(
> +          SpecLoc.getNestedNameSpecifier()->getAsType()))
> +      Diag(SpecLoc.getBeginLoc(), diag::err_decltype_in_declarator)
> +        << SpecLoc.getTypeLoc().getSourceRange();
> +  }
> +

The code here looks correct (thanks!), but please:

  (1) Move it down to where we do the other checks on the nested-name-specifier (with the comment that starts with "C++ 7.3.1.2p2")
  (2) Add a reference to the C++11 spec, quoting the paragraph that introduces this restriction.

	- Doug



More information about the cfe-commits mailing list