[llvm-bugs] [Bug 47792] New: Inconsitency between variable decltype(auto) in variables and templates

via llvm-bugs llvm-bugs at lists.llvm.org
Sat Oct 10 20:29:26 PDT 2020


https://bugs.llvm.org/show_bug.cgi?id=47792

            Bug ID: 47792
           Summary: Inconsitency between variable decltype(auto) in
                    variables and templates
           Product: clang
           Version: trunk
          Hardware: All
                OS: All
            Status: NEW
          Severity: normal
          Priority: P
         Component: C++17
          Assignee: unassignedclangbugs at nondot.org
          Reporter: anders.granlund.0 at gmail.com
                CC: blitzrakete at gmail.com, erik.pilkington at gmail.com,
                    llvm-bugs at lists.llvm.org, richard-llvm at metafoo.co.uk

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):

  https://godbolt.org/z/Y5Yc7M

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20201011/8754fa04/attachment.html>


More information about the llvm-bugs mailing list