[cfe-commits] r103767 - in /cfe/trunk: include/clang/Basic/DiagnosticParseKinds.td lib/Parse/ParseDeclCXX.cpp test/Parser/namespaces.cpp
Douglas Gregor
dgregor at apple.com
Thu May 13 22:08:22 PDT 2010
Author: dgregor
Date: Fri May 14 00:08:22 2010
New Revision: 103767
URL: http://llvm.org/viewvc/llvm-project?rev=103767&view=rev
Log:
Namespaces can only be defined at global or namespace scope. Fixes PR6596.
Added:
cfe/trunk/test/Parser/namespaces.cpp (with props)
Modified:
cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
cfe/trunk/lib/Parse/ParseDeclCXX.cpp
Modified: cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td?rev=103767&r1=103766&r2=103767&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticParseKinds.td Fri May 14 00:08:22 2010
@@ -119,6 +119,8 @@
"expected ';' after namespace name">;
def err_unexpected_namespace_attributes_alias : Error<
"attributes can not be specified on namespace alias">;
+def err_namespace_nonnamespace_scope : Error<
+ "namespaces can only be defined in global or namespace scope">;
def err_expected_semi_after_attribute_list : Error<
"expected ';' after attribute list">;
def err_expected_semi_after_static_assert : Error<
Modified: cfe/trunk/lib/Parse/ParseDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Parse/ParseDeclCXX.cpp?rev=103767&r1=103766&r2=103767&view=diff
==============================================================================
--- cfe/trunk/lib/Parse/ParseDeclCXX.cpp (original)
+++ cfe/trunk/lib/Parse/ParseDeclCXX.cpp Fri May 14 00:08:22 2010
@@ -87,6 +87,14 @@
SourceLocation LBrace = ConsumeBrace();
+ if (CurScope->isClassScope() || CurScope->isTemplateParamScope() ||
+ CurScope->isInObjcMethodScope() || CurScope->getBlockParent() ||
+ CurScope->getFnParent()) {
+ Diag(LBrace, diag::err_namespace_nonnamespace_scope);
+ SkipUntil(tok::r_brace, false);
+ return DeclPtrTy();
+ }
+
// Enter a scope for the namespace.
ParseScope NamespaceScope(this, Scope::DeclScope);
Added: cfe/trunk/test/Parser/namespaces.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Parser/namespaces.cpp?rev=103767&view=auto
==============================================================================
--- cfe/trunk/test/Parser/namespaces.cpp (added)
+++ cfe/trunk/test/Parser/namespaces.cpp Fri May 14 00:08:22 2010
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -fsyntax-only -verify %s
+
+// PR6596
+namespace g { enum { o = 0 }; }
+
+void foo() {
+ namespace a { typedef g::o o; } // expected-error{{namespaces can only be defined in global or namespace scope}}
+}
Propchange: cfe/trunk/test/Parser/namespaces.cpp
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cfe/trunk/test/Parser/namespaces.cpp
------------------------------------------------------------------------------
svn:keywords = Id
Propchange: cfe/trunk/test/Parser/namespaces.cpp
------------------------------------------------------------------------------
svn:mime-type = text/plain
More information about the cfe-commits
mailing list