title: C++ macro only works when preprocessed to a file
body: <p>I am trying to create a matching mechanism for the new <code>std::optional&lt;T&gt;</code> in C++. I've written the following macro:</p>
  
  <pre><code>#define EXPAND(x) x
  #define CAT_(x, y) x##y
  #define CAT(x, y) CAT_(EXPAND(x), EXPAND(y))
  #define if_opt__(xalt, bval, x, y)  \
  auto xalt = y;                      \
  bool bval = true;                   \
  if (xalt.has_value())               \
  for (auto x = xalt.value(); bval; bval = false)
  #define if_opt_(xalt, x, y) if_opt__(xalt, CAT(xalt, _b), x, y)
  #define if_opt(x, y) if_opt_(CAT(x, __LINE__), x, y)
  </code></pre>
  
  <p>And I've created the following example program for it:</p>
  
  <pre><code>std::optional&lt;int&gt; get(int a) {
      if (a &lt; 0) {
          return {};
      }
      return a;
  }
  
  int main(void) {
      if_opt(a, get(0)) {
          std::cout &lt;&lt; "optional matched!" &lt;&lt; std::endl;
      }
      return 0;
  }
  </code></pre>
  
  <p>However, when I try to compile the program, I get errors like 'redefinition; different basic types'. Then I preprocessed it to a file, copied the result and it compiled and worked just fine. The macro evaluated to:</p>
  
  <pre><code>auto a24 = get(0);
  bool a24_b = true;
  if (a24.has_value()) 
      for (auto a = a24.value(); a24_b; a24_b = false) {
          std::cout &lt;&lt; "optional matched!" &lt;&lt; std::endl;
      }
  </code></pre>
  
  <p>Why does it not compile using the macro itself? I'm using MSVC.</p>