Bug 53402 - [C++11] non-inline namespace can be wrongly re-opened as inline
Summary: [C++11] non-inline namespace can be wrongly re-opened as inline
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.8.0
: P3 minor
Target Milestone: 8.0
Assignee: Nathan Sidwell
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2012-05-18 16:36 UTC by Ai Azuma
Modified: 2021-12-03 00:52 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2012-05-20 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Ai Azuma 2012-05-18 16:36:42 UTC
C++11 7.3.1/7 says,

"If the optional initial inline keyword appears in a namespace-definition for a particular namespace, that namespace is declared to be an inline namespace. The inline keyword may be used on an extension-namespace-definition only if it was previously used on the original-namespace-definition for that namespace."

I understand that this paragraph prohibits "retroactive inlining" of namespaces, like the following code;

/////////////////////
namespace NS{}
inline namespace NS{}
/////////////////////

However, GCC 4.8.0 20120513 (experimental) with -std=c++11, -Wall and -Wpedantic accepts the above code without any warning.

In addition, the document that explains the implementation of libstdc++ debug mode
http://gcc.gnu.org/onlinedocs/libstdc++/manual/bk01pt03ch17s04.html#debug_mode.design.methods.coexistence
includes an example code using retroactive inlining. It may mislead some readers to think that this is standard-conforming. Therefore, even if the current implementation of libstdc++ debug mode uses retroactive inlining, it's better to avoid this style in the document.
Comment 1 Andrew Pinski 2012-05-20 19:16:35 UTC
Confirmed.
Comment 2 frankhb1989 2013-07-14 07:45:33 UTC
Confirmed in 4.8.1.
PS. Clang(trunk) treats 'non-inline namespace cannot be reopened as a inline' an error (correctly), but also complains 'inline namespace cannot be reopened as a non-inline namespace'. I'm curious why the latter should trigger a warning. G++ have no diagnostic for them at all.
Comment 3 Nathan Sidwell 2017-03-01 00:26:48 UTC
I have a fix on the modules branch.  Will commit in stage 1
Comment 4 Nathan Sidwell 2017-06-19 19:17:47 UTC
Fixed by:
2017-05-15  Nathan Sidwell  <nathan@acm.org>

	PR c++/79369
	* cp-tree.h (DECL_NAMESPACE_INLINE_P): New.
	* name-lookup.h (push_namespace): Return int, add make_inline arg.
	* name-lookup.c (push_namespace): Deal with inline directly.
	Return pushed count.
	* parser.c (cp_parser_namespace_definition): Adjust for
	push_namespace change.