Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

template non type arguments

$14.3.2 - "... A template-argument for a non-type, non-template template-parameter shall be one of:

...a constant expression (5.19) that designates the address of an object with static storage duration and external or internal linkage or a function with external or internal linkage..."

In the code shown below, I fail to understand why 'name2' and 'name3' are not allowed as non type template arguments. I am using gcc 4.7.2 on Windows.

Both 'name2' and 'name3' are names of array and hence are constant expressions. Further 'name2' is having internal linkage and 'name3' has both static and internal linkage.

template<char const *p> void f()
{

}

char name1[] = "Hi";
static char name2[]= "Hi";
const static char name3[]= "Hi";
char *name4 = "Hi";

int main()
{
    f<name1>();
    f<name2>();
    f<name3>();
    f<name4>();
}
like image 669
Chubsdad Avatar asked Jan 07 '13 09:01

Chubsdad


1 Answers

As @Nawaz correctly guessed, this is an implementation bug, not an esoteric corner of the standard.

Specifically, gcc seems to have trouble with it. Barring the last name4 which is against the standard, the rest of it compiles fine with clang

like image 89
Karthik T Avatar answered Oct 28 '22 07:10

Karthik T