title: Trigraphs in a comment, converted in c++11, ignored in c++17
body: <p>Consider the following piece of code (notice the comment):</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  int main()
  {
      int x = 1; // &lt;-- Why??/
      x += 1;
      std::cout &lt;&lt; x &lt;&lt; std::endl;
  }
  </code></pre>
  
  <p>To compile this program, I am using the GNU C++ Compiler <code>g++</code>:</p>
  
  <pre><code>$ g++ --version // g++ (Ubuntu 6.5.0-1ubuntu1~16.04) 6.5.0 20181026
  </code></pre>
  
  <p>Now, when compiling this for <em>C++11</em> and <em>C++17</em>, I get different results (and warnings).</p>
  
  <p>For C++11, <code>g++ -std=c++11 trigraph.cpp -Wall</code>:</p>
  
  <pre><code>trigraph.cpp:5:26: warning: trigraph ??/ converted to \ [-Wtrigraphs]
           int x = 1; // &lt;-- Why??/
  
  trigraph.cpp:5:16: warning: multi-line comment [-Wcomment]
           int x = 1; // &lt;-- Why??/
                      ^
  $ ./a.out
  1
  </code></pre>
  
  <p>For C++17, <code>g++ -std=c++17 trigraph.cpp -Wall</code>:</p>
  
  <pre><code>trigraph.cpp:5:26: warning: trigraph ??/ ignored, use -trigraphs to enable [-Wtrigraphs]
       int x = 1; // &lt;-- Why??/
  
  $ ./a.out
  2
  </code></pre>
  
  <p>After reading a bit about trigraphs, I understand that they were removed in C++17, thus ignored by the compiler as shown in the example above. However, in the case of C++11, even when it's in a comment it was converted!</p>
  
  <p>Now, I can see how that would affect the code if the trigraph was in  a character string for instance. But, in this example, shouldn't it be ignored since it's in a comment?</p>
  
  <p>After removing the trailing forward slash ("/") from the comment, all warnings disappeared. My question is what did exactly happen here? Why the output is different?</p>