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

            Bug ID: 119453
           Summary: Dependent name instantiation seems should not be
                    delayed inside 'noexcept' field of friend function
                    declaration
           Product: gcc
           Version: 15.0
            Status: UNCONFIRMED
          Keywords: accepts-invalid
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: rush102333 at gmail dot com
  Target Milestone: ---

With the following code, gcc does not produce any error until the friend
function 'foo' is called:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

template <typename T> struct S {
  friend void foo (S) noexcept(T::error) {}
};
//Does not fire
S<int> t;
//Fires
//void g() { foo(t); }

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

https://godbolt.org/z/c5MYoc9EK

I'm not sure but there might be some questions because the error appears right
after the instantiation of 'S' in case of default function argument:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

template <typename T> struct S {
  friend void foo (S, int a = T::error) {}
};
//Fires here
S<int> t;
//void g() { foo(t); }

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

https://godbolt.org/z/q5zqsEd5s

It appears that delayed instantiation of default arguments applies only to
member functions and function templates
(https://eel.is/c++draft/temp#decls.general-3), and a friend function of a
class template is neither, so the corresponding dependent names should be
instantiated with the class.

Please see the discussion on LLVM bug tracker:
https://github.com/llvm/llvm-project/issues/96753

Reply via email to