public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/30925] New: c++ frontend error: ?-operator parameter binding
@ 2007-02-22 11:10 istvan at benedek-home dot de
2007-02-22 23:37 ` [Bug c++/30925] " pinskia at gcc dot gnu dot org
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: istvan at benedek-home dot de @ 2007-02-22 11:10 UTC (permalink / raw)
To: gcc-bugs
When trying to compile test.cpp:
'
namespace {
struct A
{
A() {}
explicit A(short i) :m_value(i) {}
A& operator = (short i) {
m_value = i;
return *this;
}
operator short& () { return m_value; }
operator short () const { return m_value; }
private:
short m_value;
};
const A CONSTA(-1);
struct M {
void set(A& value) const {
value = 1 ? m_a : CONSTA;
}
short m_a;
};
}
int main(int argc, char** argv) {
return 0;
}
'
test.cpp: In member function 'void<unnamed>::M::set(<unnamed>::A&) const':
test.cpp:28: error: passing 'const<unnamed>::A' as 'this' argument of
'<unnamed>::A::operator short int&()' discards qualifiers
expected: convert const A to short and proceed.
Build/Plattform/Version/Config info, as requested:
Using built-in specs.
Target: sparc-sun-solaris2.9
Configured with: ../gcc-4.1.1/configure --prefix=/opt/gnu//gcc-4.1.1
--enable-languages=c,c++ --with-ld=/opt/gnu//bin/ld --with-as=/opt/gnu//bin/as
Thread model: posix
gcc version 4.1.1
/opt/gnu/gcc-4.1.1/bin/../libexec/gcc/sparc-sun-solaris2.9/4.1.1/cc1plus -E
-quiet -v -iprefix
/opt/gnu/gcc-4.1.1/bin/../lib/gcc/sparc-sun-solaris2.9/4.1.1/ test.cpp -mcpu=v7
-fpch-preprocess -o test.ii
ignoring nonexistent directory
"/opt/gnu/gcc-4.1.1/bin/../lib/gcc/sparc-sun-solaris2.9/4.1.1/../../../../sparc-sun-solaris2.9/include"
ignoring duplicate directory
"/opt/gnu//gcc-4.1.1/lib/gcc/sparc-sun-solaris2.9/4.1.1/../../../../include/c++/4.1.1"
ignoring duplicate directory
"/opt/gnu//gcc-4.1.1/lib/gcc/sparc-sun-solaris2.9/4.1.1/../../../../include/c++/4.1.1/sparc-sun-solaris2.9"
ignoring duplicate directory
"/opt/gnu//gcc-4.1.1/lib/gcc/sparc-sun-solaris2.9/4.1.1/../../../../include/c++/4.1.1/backward"
ignoring duplicate directory
"/opt/gnu//gcc-4.1.1/lib/gcc/sparc-sun-solaris2.9/4.1.1/include"
ignoring nonexistent directory
"/opt/gnu//gcc-4.1.1/lib/gcc/sparc-sun-solaris2.9/4.1.1/../../../../sparc-sun-solaris2.9/include"
#include "..." search starts here:
#include <...> search starts here:
/opt/gnu/gcc-4.1.1/bin/../lib/gcc/sparc-sun-solaris2.9/4.1.1/../../../../include/c++/4.1.1
/opt/gnu/gcc-4.1.1/bin/../lib/gcc/sparc-sun-solaris2.9/4.1.1/../../../../include/c++/4.1.1/sparc-sun-solaris2.9
/opt/gnu/gcc-4.1.1/bin/../lib/gcc/sparc-sun-solaris2.9/4.1.1/../../../../include/c++/4.1.1/backward
/opt/gnu/gcc-4.1.1/bin/../lib/gcc/sparc-sun-solaris2.9/4.1.1/include
/usr/local/include
/opt/gnu//gcc-4.1.1/include
/usr/include
End of search list.
/opt/gnu/gcc-4.1.1/bin/../libexec/gcc/sparc-sun-solaris2.9/4.1.1/cc1plus
-fpreprocessed test.ii -quiet -dumpbase test.cpp -mcpu=v7 -auxbase test
-version -o test.s
GNU C++ version 4.1.1 (sparc-sun-solaris2.9)
compiled by GNU C version 4.1.1.
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 3f2c8f59f6f5b35c02abcffa8ee26357
test.cpp: In member function 'void<unnamed>::M::set(<unnamed>::F&) const':
test.cpp:28: error: passing 'const<unnamed>::A' as 'this' argument of
'<unnamed>::A::operator short int&()' discards qualifiers
--
Summary: c++ frontend error: ?-operator parameter binding
Product: gcc
Version: 4.1.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: istvan at benedek-home dot de
GCC build triplet: sparc-sun-solaris2.9
GCC host triplet: sparc-sun-solaris2.9
GCC target triplet: sparc-sun-solaris2.9
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30925
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/30925] c++ frontend error: ?-operator parameter binding
2007-02-22 11:10 [Bug c++/30925] New: c++ frontend error: ?-operator parameter binding istvan at benedek-home dot de
@ 2007-02-22 23:37 ` pinskia at gcc dot gnu dot org
2007-02-26 14:52 ` istvan at benedek-home dot de
2007-03-09 4:34 ` bangerth at dealii dot org
2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2007-02-22 23:37 UTC (permalink / raw)
To: gcc-bugs
------- Comment #1 from pinskia at gcc dot gnu dot org 2007-02-22 23:37 -------
Hmm, ?: is a lvalue in C++. Since m_a is still an lvalue (a non modifiable one
though) we try to use "operator short&" so we get the same type, const short&,
on both sides of the ":" as short& is a closer match to const short& as for
short you have to bind a rvalue to a lvalue which is a longer way around. So
is not a bug in GCC.
If you want this to work, change "operator short" to "operator const short&"
and it will just work.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30925
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/30925] c++ frontend error: ?-operator parameter binding
2007-02-22 11:10 [Bug c++/30925] New: c++ frontend error: ?-operator parameter binding istvan at benedek-home dot de
2007-02-22 23:37 ` [Bug c++/30925] " pinskia at gcc dot gnu dot org
@ 2007-02-26 14:52 ` istvan at benedek-home dot de
2007-03-09 4:34 ` bangerth at dealii dot org
2 siblings, 0 replies; 4+ messages in thread
From: istvan at benedek-home dot de @ 2007-02-26 14:52 UTC (permalink / raw)
To: gcc-bugs
------- Comment #2 from istvan at benedek-home dot de 2007-02-26 14:52 -------
>?: is a lvalue in C++
Why? I'm missing the quotation from the Holy Standard!
IMHO:
we deal with two nonmodifiable lvalues here.
from HS 5.12 3:
Because E1 can't be converted to type 'reference to T2', the Section 'Otherwise
hits us:
'... E1 can be converted to match E2 if E1 can be implicitly converted to the
type that E2 would have if E2 were converted to an rvalue ...'
Please reconsider your opinion.
--
istvan at benedek-home dot de changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|RESOLVED |UNCONFIRMED
Resolution|INVALID |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30925
^ permalink raw reply [flat|nested] 4+ messages in thread
* [Bug c++/30925] c++ frontend error: ?-operator parameter binding
2007-02-22 11:10 [Bug c++/30925] New: c++ frontend error: ?-operator parameter binding istvan at benedek-home dot de
2007-02-22 23:37 ` [Bug c++/30925] " pinskia at gcc dot gnu dot org
2007-02-26 14:52 ` istvan at benedek-home dot de
@ 2007-03-09 4:34 ` bangerth at dealii dot org
2 siblings, 0 replies; 4+ messages in thread
From: bangerth at dealii dot org @ 2007-03-09 4:34 UTC (permalink / raw)
To: gcc-bugs
------- Comment #3 from bangerth at dealii dot org 2007-03-09 04:34 -------
(In reply to comment #0)
Take a look at this again:
> struct A
> {
> operator short& () { return m_value; }
> operator short () const { return m_value; }
> };
>
> const A CONSTA(-1);
>
> struct M {
> void set(A& value) const {
> value = 1 ? m_a : CONSTA;
> }
Since we are in M::set() const, this is a const pointer and m_a is of
type 'const short &'. On the other hand, CONSTA is of type 'const A'. So
the compiler tries to convert CONSTA to 'const short &), but there is no
member function that can do that (both of the conversion operators are
non-const and therefore can't be called; this is what the compiler complains
about).
If I understand you correctly, then the compiler should try to convert the
other way around, i.e. try to convert the 'const short &' to 'const A'. This,
however, is not possible because you declared the conversion constructor
as 'explicit'.
I believe the code is invalid, therefore.
W.
--
bangerth at dealii dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |bangerth at dealii dot org
Status|UNCONFIRMED |RESOLVED
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=30925
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-03-09 4:34 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-02-22 11:10 [Bug c++/30925] New: c++ frontend error: ?-operator parameter binding istvan at benedek-home dot de
2007-02-22 23:37 ` [Bug c++/30925] " pinskia at gcc dot gnu dot org
2007-02-26 14:52 ` istvan at benedek-home dot de
2007-03-09 4:34 ` bangerth at dealii dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).