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!
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.
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.
Google test, or gtest is an open source framework for unit testing C\C++ projects.
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).
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With