[Bug c++/97375] Unexpected top-level const retainment when declaring non-type template paramter with decltype(auto)

anders.granlund.0 at gmail dot com gcc-bugzilla@gcc.gnu.org
Wed Oct 14 07:35:02 GMT 2020


https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97375

--- Comment #1 from Anders Granlund <anders.granlund.0 at gmail dot com> ---
Here is another example of the same problem without using decltype(auto), so
the problem seems to be more general:

  #include <iostream>
  #include <type_traits>

  template<const int I>
  void f1()
  {
    std::cout << std::is_const_v<decltype(I)> << std::endl;
  }

  template<typename T, T I>
  void f2()
  {
    std::cout << std::is_const_v<decltype(I)> << std::endl;
  }

  int main()
  {
    f1<0>(); // Outputs: 0 Ok
    f2<const int, 0>(); // Outputs: 1 Not ok. Should output 0 also.
  }

Compiler explorer link for this example: https://godbolt.org/z/8ah1ax


More information about the Gcc-bugs mailing list