Last active
August 28, 2017 20:44
-
-
Save chenshuo/ed35a5615d6696be4b65a74515d598e2 to your computer and use it in GitHub Desktop.
Array as non-type template argument in C++17
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "nontype.h" | |
const char tag[] = "abc"; | |
int main() | |
{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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