Skip to content

Instantly share code, notes, and snippets.

@chenshuo
Last active August 28, 2017 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chenshuo/ed35a5615d6696be4b65a74515d598e2 to your computer and use it in GitHub Desktop.
Save chenshuo/ed35a5615d6696be4b65a74515d598e2 to your computer and use it in GitHub Desktop.
Array as non-type template argument in C++17
#include "nontype.h"
const char tag[] = "abc";
int main()
{
}
template <const char* T>
struct X {
};
extern const char tag[];
typedef X<tag> Y;
// $ clang++ nontype.cc -std=c++1z
// nontype.h:6:11: error: non-type template argument refers to subobject '&tag'
// typedef X<tag> Y;
// ^
// 1 error generated.
const char tag2[] = "abc";
struct Z {
X<tag2> x_;
};
// $ g++ nontype.cc -c -std=c++17
// nontype.h:15:8: warning: 'Z' has a field 'Z::x_' whose type uses the anonymous namespace [-Wsubobject-linkage]
// struct Z {
// ^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment