title: How are ambiguous grammar resolved?
body: <p>Is there a general rule on how to resolve ambiguous grammar?</p>
  
  <p>In particular, a <a href="https://timsong-cpp.github.io/cppwp/n4140/expr.post#nt:pseudo-destructor-name" rel="nofollow noreferrer"><em>pseudo-destructor-name</em></a> includes these production rules</p>
  
  <blockquote>
    <p>nested-name-specifier<sub>opt</sub> type-name :: ~ type-name</p>
    
    <p>nested-name-specifier<sub>opt</sub> ~ type-name</p>
  </blockquote>
  
  <p>And <a href="https://timsong-cpp.github.io/cppwp/n4140/expr.prim.general#nt:nested-name-specifier" rel="nofollow noreferrer"><em>nested-name-specifier</em></a> includes</p>
  
  <blockquote>
    <p>nested-name-specifier identifier ::</p>
    
    <p>type-name ::</p>
  </blockquote>
  
  <p>Given the following</p>
  
  <pre><code>struct A
  {
      struct B {};
      B b;
  };
  
  A a;
  a.b.A::B::~B();
  </code></pre>
  
  <p>Which of the following production is choosed for the last line?</p>
  
  <blockquote>
    <p>type-name :: type-name :: ~ type-name</p>
    
    <p>type-name :: identifier :: ~ type-name</p>
  </blockquote>
  
  <p>This has significance in a templated context, since <a href="https://timsong-cpp.github.io/cppwp/n4140/temp.res#5" rel="nofollow noreferrer">[temp.res]</a></p>
  
  <blockquote>
    <p>In a nested-name-specifier that immediately contains a nested-name-specifier that depends on a template parameter, the identifier or simple-template-id is implicitly assumed to name a type, without the use of the typename keyword.</p>
  </blockquote>