Template parameter linkage

Template parameter linkage

Post by Yechezkel » Wed, 18 Mar 2009 02:47:57


In N2798, 3.5p8 comment 30:

30) A class template always has external linkage, and the requirements
of 14.3.1 and 14.3.2 ensure that the template arguments will also have
appropriate linkage.

I presume this comment refers to the fact that template parameters
must have external linkage. Now that this restriction has been lifted
shouldn't the comment be changed?

Yechezkel Mett

--
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@netlab.cs.rpi.edu]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.yqcomputer.com/ ]
 
 
 

1. Is the linkage of the template parameter checked during explicit specialisation?

2. Is the linkage of the template parameter checked during explicit specialisation?

I am trying to understand if one is allowed to specialise a template with a pointer to a
function which does not have external linkage.

According to 14.3.2/1, template argument may be an address of a function, but only if it
has external linkage.
According to 3.5/3, functions declared static have external linkage.
So, I expected a compiler error from
static void foo() {}
template<void (*p)()> void test() {}
template void test<&foo>();

But Comeau 4.3.3, Intel C++ 9, VC7.1 and VC8 compiled this without any warnings. Only g++
3.4.2 failed to compile with a "it must be the address of a function with external
linkage" error.

But if we have a class template and not a function template
static void foo() {}
template<void (*p)()> struct A {};
template struct A<&foo>;
Then all these 5 compilers fail to compile the code and show the correct error.

Did I misread something in the standard, or Comeau, Intel and VC compilers have a bug?

Valentin Samko - http://www.yqcomputer.com/

[ See http://www.yqcomputer.com/ ]
[ comp.lang.c++.moderated. First time posters: Do this! ]

3. Is the linkage of the template parameter checked during explicit specialisation?

4. Specializing a template template-parameters with a template template class.

5. Specializing a template template-parameters with a template template class.

6. Specializing a template template-parameters with a template template class.

7. decltype as a template parameter when containing reference to another template parameter.

8. decltype as a template parameter when containing reference to another template parameter.

9. skipping template parameters inside template parameters

10. Using declaration inside first template parameter as default value for second template parameter.

11. Must variadic template parameters occur at the end of the template parameter list?

12. Must variadic template parameters occur at the end of the template parameter list?

13. trying to hide an external-linkage identifier with an internal-linkage one

14. Xcode precompiled headers cause C linkage vs. C++ linkage errors

15. Template with C linkage errors -- please help