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

            Bug ID: 122400
           Summary: qualified friend declaration doesn't search names in
                    the declared scope
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ykakeyama3014 at gmail dot com
  Target Milestone: ---

Following code is rejected by GCC trunk:

namespace outer {

namespace inner {

inline constexpr bool foo = true;

using bar = int;

}  // namespace inner

auto func() noexcept(inner::foo) -> inner::bar;

namespace inner {

struct S {
  friend auto outer::func() noexcept(foo) -> bar;
};

}  // namespace inner

}  // namespace outer

Errors are follows:

source.cpp:16:38: error: ‘foo’ was not declared in this scope; did you mean
‘outer::inner::foo’?
   16 |   friend auto outer::func() noexcept(foo) -> bar;
      |                                      ^~~
      |                                      outer::inner::foo
source.cpp:5:23: note: ‘outer::inner::foo’ declared here
    5 | inline constexpr bool foo = true;
      |                       ^~~
source.cpp:16:46: error: ‘bar’ does not name a type
   16 |   friend auto outer::func() noexcept(foo) -> bar;
      |                                              ^~~

In the qualified friend declaration, name lookup should search ::outer first
and then ::outer::inner according to [basic.lookup.unqual]#6. However, it seems
GCC currently searches only the first case, not searching ::outer::inner.

Reply via email to