I have the following example code which uses a string literal as a template parameter, such that the base class template can access the string.
The code compiles, but I get a warning which I do not fully understand:
warning: ‘ns::bar::type’ has a base ‘ns::base<((const char*)(& ns::bar::name))>’ whose type uses the anonymous namespace [enabled by default]
Working example code below:
// "test.h"
#pragma once
namespace ns
{
template <char const* str>
struct base
{
const char *name() const { return str; }
};
namespace bar
{
static constexpr char name[] = "bar";
struct type : base<name> {}; // <-- this line here
}
}
// main.cpp
#include <iostream>
#include "test.h"
int main()
{
ns::bar::type f;
std::cout << f.name() << std::endl;
return 0;
}
So my questions are:
- What does this warning mean?
- Is it safe to pass a string literal as a template parameter in the way that I am doing here?
(Note this is with gcc 4.7.2)