Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

g++ -fsyntax-only unit test

Tags:

g++

I'm trying to figure out if

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!

like image 248
anon Avatar asked Apr 14 '10 04:04

anon


People also ask

What is G unit testing?

GUnit is a framework for developing unit tests for Gosu classes. It is integrated within Guidewire Studio and allows users to develop and execute test cases using Studio's GUI. When running the tests, Studio runs an in-memory version of the Guidewire application.

What is Gtest and Gmock?

In real system, these counterparts belong to the system itself. In the unit tests they are replaced with mocks. Gtest is a framework for unit testing. Gmock is a framework imitating the rest of your system during unit tests.

Is Google Test open source?

Google test, or gtest is an open source framework for unit testing C\C++ projects.

How do I download Google Test?

Download Google Test from the official repository and extract the contents of googletest-master into an empty folder in your project (for example, Google_tests/lib). Alternatively, clone Google Test as a git submodule or use CMake to download it (instructions below will not be applicable in the latter case).


1 Answers

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.

like image 92
vladr Avatar answered Oct 25 '22 23:10

vladr