Wednesday, March 1, 2017

Digest for comp.lang.c++@googlegroups.com - 25 updates in 3 topics

"Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com>: Mar 01 05:40AM +0100

On 2/28/2017 7:25 PM, Paavo Helde wrote:
> defined in every translation unit in which it is implicitly instantiated
> (14.7.1) unless the corresponding specialization is explicitly
> instantiated (14.7.2) in some translation unit; no diagnostic is required."
 
Oh. So for Juha's example one formally needs
 
template<> int foo<unsigned>() { return 2; }
template foo<unsigned>();
 
Hurray for redundancy.
 
 
> instantiation and appear to work fine without it (and with "no
> diagnostic produced"). See the recent thread "does the language
> guarantee `explicit specialization' will generate the code ?".
 
I tried the following test code with g++ and MSVC:
 
 
[file "foo.hpp"]
#pragma once
template<class> int foo() { return 1; }
[/file]
 
[file "a.cpp"]
#include "foo.hpp"
 
template<> auto foo<unsigned>() -> int { return 2; }
#ifdef INSTANTIATE
template auto foo<unsigned>() -> int;

No comments: