
Easy way to detect where the C++11/C++14 features are used in a C++ project - virtualcpp
http://www.cppdepend.com/blog/?p=144
======
a_twig
Disable C++11/14 with a compiler flag (or use an old compiler version) and try
to build the project :-P

~~~
wfunction
The problem is the compiler can't necessarily even parse the file with an
older version of the language.

~~~
geezerjay
That is not true. When GCC is used to compile a C++11 project with the
--std=c++03 or --std=c++98 flags, it parses the whole source tree but throws
errors whenever it catches C++11 features.

For example, this is the error message GCC returns when it catches an
"override" keyword when compiling with --std=c++03 flags:

> controls (override/final) only available with -std=c++11 or -std=gnu++11

~~~
wfunction
Nah, it's true. Here's dumb example, where the compiler errors totally miss
make_unique:

    
    
      #include <memory>
      #define u8 }{
      struct Foo {
      	char const *foo() {
      		char const *r = u8"foo";
      		std::make_unique<int>(1);
      		return r;
      	}
      };
    

Maybe now you can argue it won't happen in _practice_ , and my intuition is
you'd still be wrong for large projects, but I don't have the time to try to
come with a more realistic example. Hopefully this is enough to get the point
across though. The syntax has changed, and the compiler can be only so smart
trying to decipher it efficiently.

~~~
geezerjay
Here's another example:

Test code:

#include <memory>

int main()

{

    
    
            std::unique_ptr<int> pPointer = std::make_unique<int>();
            return 0;

}

Here's the GCC output (v4.9.2) with C++14:

geezerjay@debian:tmp$ g++ --std=c++14 main.c++

geezerjay@debian:tmp$

And now the GCC output with C++11:

geezerjay@debian:tmp$ g++ --std=c++14 main.c++

main.c++: In function ‘int main()’:

main.c++:5:34: error: ‘make_unique’ is not a member of ‘std’
std::unique_ptr<int> pPointer = std::make_unique<int>();

    
    
                                      ^

main.c++:5:51: error: expected primary-expression before ‘int’

    
    
      std::unique_ptr<int> pPointer = std::make_unique<int>();

geezerjay@debian:tmp$

Perhaps recent GCC versions catch this issue, but errors are indeed thrown if
make_unique, a C++14 feature, is present while compiling C++11 code.

------
acidburn1995
An easier way would be when you change -std=c++1y to -std=c++03 it won't
compile.

------
wcr3
thanks for the ad

