[Bug c++/85087] call to a non-const member function on a const lvalue accepted

2021-08-06 Thread redi at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85087

Jonathan Wakely  changed:

   What|Removed |Added

 Status|NEW |RESOLVED
 Resolution|--- |INVALID

--- Comment #3 from Jonathan Wakely  ---
(In reply to Martin Sebor from comment #0)
> While looking at bug 85043 I noticed that in the test case below, GCC
> correctly rejects the attempt to convert the const reference to B to A in
> the call to g()

No, it allows the conversion, but that produces an rvalue which can't bind to
the A& parameter of g.

> but it accepts the same invalid conversion in the context
> where a a non-const member function on the result of the conversion is
> called.  Other compilers reject both conversions.

Why should it be rejected? ((A)b) calls the conversion operator to get a const
A& and then initializes an rvalue of type A from that. The rvalue is not const,
and you can call the member function.

i.e. equivalent to:

  static_cast(b.operator const A&()).f();

or:

  A(b).f();

both of which are accepted, as they should be.

EDG accepts the static_cast version, but not A(b).f(), I don't know why. But
I think EDG has the bug here, not GCC.

[Bug c++/85087] call to a non-const member function on a const lvalue accepted

2021-08-01 Thread pinskia at gcc dot gnu.org via Gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85087

Andrew Pinski  changed:

   What|Removed |Added

   Last reconfirmed|2018-03-28 00:00:00 |2021-8-1

--- Comment #2 from Andrew Pinski  ---
clang, gcc, and msvc all accepts this
ICC rejects this.

[Bug c++/85087] call to a non-const member function on a const lvalue accepted

2018-03-28 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85087

Martin Sebor  changed:

   What|Removed |Added

 Status|UNCONFIRMED |NEW
   Last reconfirmed||2018-03-28
 Ever confirmed|0   |1

[Bug c++/85087] call to a non-const member function on a const lvalue accepted

2018-03-26 Thread msebor at gcc dot gnu.org
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=85087

Martin Sebor  changed:

   What|Removed |Added

   Keywords||accepts-invalid

--- Comment #1 from Martin Sebor  ---
The code has been accepted since at least GCC 4 so it's not a regression.

For reference, EDG eccp 4.13 prints the following errors:

"u.C", line 11: error: qualifiers dropped in binding reference of type "A &" to
  initializer of type "const A"
g ((A)b);  // error: good
   ^

"u.C", line 13: error: the object has type qualifiers that are not compatible
  with the member function "A::f"
object type is: const A
((A)b).f ();   // accepted: bug
^

2 errors detected in the compilation of "u.C".