[Bug c++/60565] Bogus not-in-scope error

2021-07-28 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=60565

Andrew Pinski  changed:

   What|Removed |Added

  Known to work||8.0
 Status|NEW |RESOLVED
   Target Milestone|--- |8.0
   Keywords||rejects-valid
 Resolution|--- |FIXED

--- Comment #6 from Andrew Pinski  ---
This works in GCC 8 and above.

[Bug c++/60565] Bogus not-in-scope error

2014-03-18 Thread patrick at parcs dot ath.cx
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60565

--- Comment #1 from patrick at parcs dot ath.cx ---
Er, sorry, the call to foo () within main ought to be B::foo ().


[Bug c++/60565] Bogus not-in-scope error

2014-03-18 Thread redi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60565

--- Comment #2 from Jonathan Wakely redi at gcc dot gnu.org ---
(In reply to patrick from comment #0)
 $ g++ -c exc.C
 exc.C:8:26: warning: declaration of ‘void B::foo()’ with C language linkage
 [enabled by default]
  extern C void foo ();
   ^
 exc.C:3:21: warning: conflicts with previous declaration ‘void A::foo()’
 [enabled by default]
  extern C void foo () throw ();
  ^
 exc.C:8:26: warning: due to different exception specifications [enabled by
 default]
  extern C void foo ();
   ^

This inconsistency makes the declaration of B::foo() ill-formed.


 exc.C: In function ‘int main()’:
 exc.C:14:5: error: ‘foo’ is not a member of ‘B’
  B::foo ();
  ^

This does not correspond to the code above, I don't know whether the code or
the error is what you mean to post.

In either case, I don't think this is bogus. The function's name is foo for
linkage purposes, but as it isn't declared in the global namespace you still
need to qualify it to call it. If you call A::foo() it will compile, or if you
fix the ill-formed redeclaration as B::foo() then you can call it as B::foo().
You cannot call it unqualified though (unless you add a using declaration or
using directive or redeclare it at global scope).

[Bug c++/60565] Bogus not-in-scope error

2014-03-18 Thread redi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60565

--- Comment #3 from Jonathan Wakely redi at gcc dot gnu.org ---
(In reply to patrick from comment #1)
 Er, sorry, the call to foo () within main ought to be B::foo ().

OK, in that case you need to fix the declaration of B::foo() if you want to
call it.  I think G++ is ignoring the inconsistent declaration of B::foo(). I'm
not sure if that's correct, or whether it should give an error at that point.


[Bug c++/60565] Bogus not-in-scope error

2014-03-18 Thread patrick at parcs dot ath.cx
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60565

--- Comment #4 from patrick at parcs dot ath.cx ---
(In reply to Jonathan Wakely from comment #3)
 (In reply to patrick from comment #1)
  Er, sorry, the call to foo () within main ought to be B::foo ().
 
 OK, in that case you need to fix the declaration of B::foo() if you want to
 call it.  I think G++ is ignoring the inconsistent declaration of B::foo().
 I'm not sure if that's correct, or whether it should give an error at that
 point.

I think the compiler should not ignore the ill-formed declaration because 1)
the diagnostic emitted is just a warning and 2) acknowledging the declaration
even though it is ill-formed is consistent with the behavior of the following
test case:


namespace A
{
extern C void foo (int);
}

namespace B
{
extern C void foo ();
}

int
main ()
{
B::foo ();
}

$ g++ -c exc.c
exc.C:9:29: warning: declaration of ‘void B::foo(int)’ with C language linkage
[enabled by default]
 extern C void foo (int);
 ^
exc.C:3:21: warning: conflicts with previous declaration ‘void A::foo()’
[enabled by default]
 extern C void foo ();
 ^

Here, a much more egregious bug may have been introduced yet the the second
ill-formed declaration is still usable.

[Bug c++/60565] Bogus not-in-scope error

2014-03-18 Thread redi at gcc dot gnu.org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=60565

Jonathan Wakely redi at gcc dot gnu.org changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2014-03-18
 Ever confirmed|0   |1

--- Comment #5 from Jonathan Wakely redi at gcc dot gnu.org ---
Yes, the current behaviour is certainly not consistent.

Clang warns about the missing exception-specification but allows B::foo() to be
called, as you expect.