[cfe-dev] C++ using-directive parsing

Douglas Gregor dgregor at apple.com
Mon Dec 29 13:06:40 PST 2008


On Dec 28, 2008, at 12:32 AM, Piotr Rak wrote:
> 2008/12/27 Douglas Gregor <dgregor at apple.com>:
>
> Yes, I initially had ParseUsingDirectiveOrDeclaration during  
> evolution.
> Later had short, failed attempt implementing c++0x:
> using-directive:
>      attribute-specifier[opt] using namespace ::[opt]
> nested-name-specifier[opt] namespace-name ;
>
> requiring tentative parsing, and forgot change it back. Fixed now in
> attached version.

Thanks.

> I made additional change, now ActOnUsingDirective is not called when
> we fail parse CXXScopeSpec or identifier. Is this ok, or we should
> create invalid decl in such cases?

This is okay. If the parsing failed and we've emitted an error  
already, there's no sense is calling into the Action module. If, for  
example, we had already creating the decl and then found a parse  
error, we'd want to call into the Action module to tell it that the  
decl is now invalid.

+  if (!(getLangOptions().CPlusPlus || getLangOptions().CPlusPlus0x)
+      && NamespaceNameOnly) {

You only need to check for getLangOptions().CPlusPlus here... we won't  
ever have CPlusPlus0x without CPlusPlus. Typically, the "if" condition  
should be folded into the assertion (so it all goes away in release  
mode), but in this case I don't think the assertion itself is all that  
important.

+  } else {
+    Diag(IdentLoc, diag::err_expected_namespace_name);
+    // FIXME: if SS.isSet() we could note about NamespcName not being
+    // member of DC, or not namespace name.
+  }

Instead of mentioning DC (which means trying to format it into a  
readable name in the error message), I suggest just underlying the  
range with, e.g.,

	Diag(IdentLoc, diag::err_expected_namespace_name) <<  
SS.getSourceRange();

Anyway, these are minor things. If you would send the updated cxx- 
using-directive.cpp test case you mentioned, I'll be happy to  
integrate your patch into the Clang repository. Thanks!

	- Doug



More information about the cfe-dev mailing list