Bug 60786 - In C++11 an explicit instantiation with an unqualified name must be in the right namespace
Summary: In C++11 an explicit instantiation with an unqualified name must be in the ri...
Status: RESOLVED DUPLICATE of bug 56480
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 4.9.0
: P3 normal
Target Milestone: 7.0
Assignee: Not yet assigned to anyone
URL:
Keywords: accepts-invalid
Depends on:
Blocks:
 
Reported: 2014-04-08 12:20 UTC by Jonathan Wakely
Modified: 2021-08-04 20:42 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail: 4.8.2, 4.9.1, 5.0
Last reconfirmed: 2014-12-14 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jonathan Wakely 2014-04-08 12:20:15 UTC
This should not be accepted in C++11 mode:

namespace A {
  template<typename T> struct B { };
}

using A::B;
template class B<int>;


[temp.explicit] p3:
"An explicit instantiation shall appear in an enclosing namespace of its template. If the name declared in the explicit instantiation is an unqualified name, the explicit instantiation shall appear in the namespace where its template is declared or, if that namespace is inline (7.3.1), any namespace from its enclosing namespace set."

This is a change from C++03:

"A definition of a class template or class member template shall be in scope at the point of the explicit instantiation of the class template or class member template."
Comment 1 Jonathan Wakely 2014-04-15 19:06:17 UTC
Author: redi
Date: Tue Apr 15 19:05:45 2014
New Revision: 209431

URL: http://gcc.gnu.org/viewcvs?rev=209431&root=gcc&view=rev
Log:
	PR c++/60786
	* testsuite/20_util/shared_ptr/requirements/explicit_instantiation/
	1.cc: Fix invalid explicit instantiations with unqualified names.
	* testsuite/20_util/shared_ptr/requirements/explicit_instantiation/
	2.cc: Likweise.
	* testsuite/20_util/tuple/53648.cc: Likweise.
	* testsuite/20_util/weak_ptr/requirements/explicit_instantiation/1.cc:
	Likewise.
	* testsuite/20_util/weak_ptr/requirements/explicit_instantiation/2.cc:
	Likewise.
	* testsuite/23_containers/unordered_map/requirements/
	debug_container.cc: Likewise.
	* testsuite/23_containers/unordered_map/requirements/
	explicit_instantiation/3.cc: Likewise.
	* testsuite/23_containers/unordered_multimap/requirements/debug.cc:
	Likewise.
	* testsuite/23_containers/unordered_multimap/requirements/
	explicit_instantiation/3.cc: Likewise.
	* testsuite/23_containers/unordered_multiset/requirements/debug.cc:
	Likewise.
	* testsuite/23_containers/unordered_multiset/requirements/
	explicit_instantiation/3.cc: Likewise.
	* testsuite/23_containers/unordered_set/requirements/
	debug_container.cc: Likewise.
	* testsuite/23_containers/unordered_set/requirements/
	explicit_instantiation/3.cc: Likewise.

Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/testsuite/20_util/shared_ptr/requirements/explicit_instantiation/1.cc
    trunk/libstdc++-v3/testsuite/20_util/shared_ptr/requirements/explicit_instantiation/2.cc
    trunk/libstdc++-v3/testsuite/20_util/tuple/53648.cc
    trunk/libstdc++-v3/testsuite/20_util/weak_ptr/requirements/explicit_instantiation/1.cc
    trunk/libstdc++-v3/testsuite/20_util/weak_ptr/requirements/explicit_instantiation/2.cc
    trunk/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/debug_container.cc
    trunk/libstdc++-v3/testsuite/23_containers/unordered_map/requirements/explicit_instantiation/3.cc
    trunk/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/debug.cc
    trunk/libstdc++-v3/testsuite/23_containers/unordered_multimap/requirements/explicit_instantiation/3.cc
    trunk/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/debug.cc
    trunk/libstdc++-v3/testsuite/23_containers/unordered_multiset/requirements/explicit_instantiation/3.cc
    trunk/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/debug_container.cc
    trunk/libstdc++-v3/testsuite/23_containers/unordered_set/requirements/explicit_instantiation/3.cc
Comment 2 Jonathan Wakely 2014-04-15 19:08:18 UTC
I've fixed the libstdc++ tests so they don't rely on this bug
Comment 3 Ville Voutilainen 2014-12-14 15:37:38 UTC
Clang rejects the code.
Comment 4 Andrew Pinski 2021-08-04 20:42:06 UTC
In GCC7+, we started having a pedantic warning (only with -pedantic or -Wpedantic):
<source>:6:16: warning: explicit instantiation of 'template<class T> struct A::B' outside its namespace must use a nested-name-specifier [-Wpedantic]
 template class B<int>;
                ^~~~~~

This is a dup of bug 56480.

*** This bug has been marked as a duplicate of bug 56480 ***