title: GCC & Cmake: Do not use newer features
body: <p>I am trying to compile some code with GCC and CMake. In the CMakeLists.txt file, I am setting the target properties like this:</p>
  
  <pre><code>set_target_properties(${example_name} PROPERTIES
          CXX_STANDARD 14
          CXX_STANDARD_REQUIRED YES
          CXX_EXTENSIONS NO
          )
  </code></pre>
  
  <p>I would like to know how it is possible to force Cmake/Gcc to only use features available in C++14 and nothing newer. I would like a compile time error (not a warning). The reason I want this is that I will eventually need to port this code over to a different system with a compiler that only supports C++14. </p>
  
  <p>To test the above, I add some obvious C++17 features: </p>
  
  <pre><code>namespace bob::hope {
  void bar() {
    if constexpr (true) {
      return;
    }
  }
  }
  </code></pre>
  
  <p>But instead of giving me an error, it just throws a warning. Specifically, if I turn on some warnings:</p>
  
  <pre><code>add_compile_options(-Wall -Wextra -Wpedantic)
  </code></pre>
  
  <p>then I get </p>
  
  <pre><code>warning: nested namespace definitions only available with -std=c++1z or -std=gnu++1z [-Wpedantic]
  warning: ‘if constexpr’ only available with -std=c++1z or -std=gnu++1z
  </code></pre>
  
  <p>But the code otherwise compiles without error. </p>
  
  <p>So how can I configure Cmake to disallow newer language features?</p>