]> granicus.if.org Git - clang/commitdiff
Downgrade the error about re-opening an inline namespace as non-inline
authorDouglas Gregor <dgregor@apple.com>
Fri, 20 May 2011 15:48:31 +0000 (15:48 +0000)
committerDouglas Gregor <dgregor@apple.com>
Fri, 20 May 2011 15:48:31 +0000 (15:48 +0000)
to a warning, since apparently libstdc++'s debug mode does this (and
we can recover safely). Add a Fix-It to insert the "inline", just for kicks.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@131732 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclCXX.cpp
test/CXX/dcl.dcl/basic.namespace/namespace.def/p7.cpp

index 84106856ca76feceb73dfeefb13d5513513865e9..d96b40ac7eefa2012b6e2dede248b02dc29913f0 100644 (file)
@@ -502,6 +502,8 @@ def err_static_assert_expression_is_not_constant : Error<
   "static_assert expression is not an integral constant expression">;
 def err_static_assert_failed : Error<"static_assert failed \"%0\"">;
 
+def warn_inline_namespace_reopened_noninline : Warning<
+  "inline namespace cannot be re-opened as a non-inline namespace">;
 def err_inline_namespace_mismatch : Error<
   "%select{|non-}0inline namespace "
   "cannot be reopened as %select{non-|}0inline">;
index c6a0490c2472245c839e72d9be470cbdf66f6b5a..90c840ba7faa150263dacb08cd24dea1986747ad 100644 (file)
@@ -4657,10 +4657,18 @@ Decl *Sema::ActOnStartNamespaceDef(Scope *NamespcScope,
       // This is an extended namespace definition.
       if (Namespc->isInline() != OrigNS->isInline()) {
         // inline-ness must match
-        Diag(Namespc->getLocation(), diag::err_inline_namespace_mismatch)
-          << Namespc->isInline();
+        if (OrigNS->isInline()) {
+          // The user probably just forgot the 'inline', so suggest that it
+          // be added back.
+          Diag(Namespc->getLocation(), 
+               diag::warn_inline_namespace_reopened_noninline)
+            << FixItHint::CreateInsertion(NamespaceLoc, "inline ");
+        } else {
+          Diag(Namespc->getLocation(), diag::err_inline_namespace_mismatch)
+            << Namespc->isInline();
+        }
         Diag(OrigNS->getLocation(), diag::note_previous_definition);
-        Namespc->setInvalidDecl();
+
         // Recover by ignoring the new namespace's inline status.
         Namespc->setInline(OrigNS->isInline());
       }
index 198b0135187ec2cd26d92301595539e666ed4a2d..e3d3d683ceb790ad781401e3ea2d982678d7c1d6 100644 (file)
@@ -3,7 +3,7 @@
 namespace NIL {} // expected-note {{previous definition}}
 inline namespace NIL {} // expected-error {{cannot be reopened as inline}}
 inline namespace IL {} // expected-note {{previous definition}}
-namespace IL {} // expected-error {{cannot be reopened as non-inline}}
+namespace IL {} // expected-warning{{inline namespace cannot be re-opened as a non-inline namespace}}
 
 namespace {} // expected-note {{previous definition}}
 inline namespace {} // expected-error {{cannot be reopened as inline}}