开发者

g++ -fsyntax-only unit test

开发者 https://www.devze.com 2022-12-26 14:07 出处:网络
I\'m trying to figure out if开发者_Python百科 g++ -fsyntax-only does only syntax checking or if it expands templates too.

I'm trying to figure out if

开发者_Python百科
g++ -fsyntax-only

does only syntax checking or if it expands templates too.

Thus, I ask stack overflow for help:

Is there a way to write a program so that syntactically it's valid, but when template expansion is done, an error occurs?

Thanks!


Is there a way to write a program so that syntactically it's valid, but when template expansion is done, an error occurs?

Depends on whether your definition of syntactically valid is g++'s -fsyntax-only or not.

The following simple test program illustrates this and, I believe, answers your question:

// test.cpp
template< bool > struct test;
template< > struct test< true > { };

int main(void) {
  test< false > t;
  return 0;
}

Attempting to build:

$ g++ /tmp/sa.cpp
test.cpp: In function `int main()':
test.cpp:6: error: aggregate `test< false> t' has incomplete type and
  cannot be defined

$ g++ -fsyntax-only /tmp/sa.cpp
test.cpp: In function `int main()':
test.cpp:6: error: aggregate `test< false> t' has incomplete type and
  cannot be defined

So yes, -fsyntax-only does perform template expansion.

0

精彩评论

暂无评论...
验证码 换一张
取 消