<html>
    <head>
      <base href="https://bugs.llvm.org/">
    </head>
    <body><table border="1" cellspacing="0" cellpadding="8">
        <tr>
          <th>Bug ID</th>
          <td><a class="bz_bug_link 
          bz_status_NEW "
   title="NEW - Inconsitency between variable decltype(auto) in variables and templates"
   href="https://bugs.llvm.org/show_bug.cgi?id=47792">47792</a>
          </td>
        </tr>

        <tr>
          <th>Summary</th>
          <td>Inconsitency between variable decltype(auto) in variables and templates
          </td>
        </tr>

        <tr>
          <th>Product</th>
          <td>clang
          </td>
        </tr>

        <tr>
          <th>Version</th>
          <td>trunk
          </td>
        </tr>

        <tr>
          <th>Hardware</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>OS</th>
          <td>All
          </td>
        </tr>

        <tr>
          <th>Status</th>
          <td>NEW
          </td>
        </tr>

        <tr>
          <th>Severity</th>
          <td>normal
          </td>
        </tr>

        <tr>
          <th>Priority</th>
          <td>P
          </td>
        </tr>

        <tr>
          <th>Component</th>
          <td>C++17
          </td>
        </tr>

        <tr>
          <th>Assignee</th>
          <td>unassignedclangbugs@nondot.org
          </td>
        </tr>

        <tr>
          <th>Reporter</th>
          <td>anders.granlund.0@gmail.com
          </td>
        </tr>

        <tr>
          <th>CC</th>
          <td>blitzrakete@gmail.com, erik.pilkington@gmail.com, llvm-bugs@lists.llvm.org, richard-llvm@metafoo.co.uk
          </td>
        </tr></table>
      <p>
        <div>
        <pre>Consider the following program:

  #include <iostream>
  #include <type_traits>

  template<decltype(auto) N>
  void f()
  {
    std::cout << std::is_same_v<decltype(N), int> << std::endl;
  }

  int main()
  {
    const int i = 0;

    f<i>();

    decltype(auto) N = i;
    std::cout << std::is_same_v<decltype(N), const int> << std::endl;
  }

When compiling it with  -std=c++17 -pedantic-errors  and the running it the
following is outputed:

  1
  1

This means that the two decltype(auto) deductions behaved differently since
they deduced different types ( N = int and N = const int ). I expect them to
behave the same way.

Note that gcc gives the expected result ( N = const int  for both deductions ).

Link to compiler explorer (clang to the left, gcc to the right):

  <a href="https://godbolt.org/z/Y5Yc7M">https://godbolt.org/z/Y5Yc7M</a></pre>
        </div>
      </p>


      <hr>
      <span>You are receiving this mail because:</span>

      <ul>
          <li>You are on the CC list for the bug.</li>
      </ul>
    </body>
</html>