2

I'm trying to understand if what I'm seeing is an MSVC compiler bug or a misunderstanding on my part. I'm trying to use a simple compile-time string literal template parameter, like so:

constexpr const char teststr[] = "teststr";

template <const char *N>
struct Test {
  static constexpr const char *name = N;
};

using TEST = Test<teststr>;

However, MSVC reports that the teststr parameter is not a compile-time expression: error C2975: 'Test': invalid template argument for 'N', expected compile-time constant expression (on the using TEST line).

Is this my mistake, or a compiler bug? I am using Visual Studio 2017 version 15.1.

0

2 Answers 2

1

It is a compiler bug.

In addition, it is a C++11 feature to permit addresses of objects with internal linkage in template arguments, not C++14.

Sign up to request clarification or add additional context in comments.

Comments

0

Is it important that name is static ?

This compiles with MSVC 2015:

char teststr[] = "teststr";

template <const char *N>
struct Test
{
    const char *name = N;
};

using TEST = Test<teststr>;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.