public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66615] New: Ambiguous conversion operators, explicit unambiguous conversion operator and copy initialization
@ 2015-06-21 13:24 fynjycfdby at gmail dot com
  2015-06-21 14:14 ` [Bug c++/66615] Ambiguous conversion operators, explicit conversion operator and copy-initialization trippels at gcc dot gnu.org
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: fynjycfdby at gmail dot com @ 2015-06-21 13:24 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 66615
           Summary: Ambiguous conversion operators, explicit unambiguous
                    conversion operator and copy initialization
           Product: gcc
           Version: 5.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: fynjycfdby at gmail dot com
  Target Milestone: ---

The following code is wrongly accepted, the output is an arbitrary number:

-----
#include <iostream>

struct A {
    explicit operator int() {
        return 42;
    }

    operator float() {
        return 123.0f;
    }

    operator double() {
        return 456.0;
    }
};

int main() {
    int i = A(); // note copy-initialization
    std::cout << i << std::endl;
}
-----

With -Wall it generates a warning:

main.cpp: In function 'int main()':
main.cpp:19:18: warning: 'i' is used uninitialized in this function
[-Wuninitialized]
     std::cout << i << std::endl;


The correct behavior should be failure to compile, because the operator int()
is explicit, and other implicit conversion operators make conversion to int
ambiguous.

I'm using MacPorts g++-mp-5

$ g++-mp-5 -v
Using built-in specs.
COLLECT_GCC=g++-mp-5
COLLECT_LTO_WRAPPER=/opt/local/libexec/gcc/x86_64-apple-darwin14/5.1.0/lto-wrapper
Target: x86_64-apple-darwin14
Configured with:
/opt/local/var/macports/build/_opt_mports_dports_lang_gcc5/gcc5/work/gcc-5.1.0/configure
--prefix=/opt/local --build=x86_64-apple-darwin14
--enable-languages=c,c++,objc,obj-c++,lto,fortran,java
--libdir=/opt/local/lib/gcc5 --includedir=/opt/local/include/gcc5
--infodir=/opt/local/share/info --mandir=/opt/local/share/man
--datarootdir=/opt/local/share/gcc-5 --with-local-prefix=/opt/local
--with-system-zlib --disable-nls --program-suffix=-mp-5
--with-gxx-include-dir=/opt/local/include/gcc5/c++/ --with-gmp=/opt/local
--with-mpfr=/opt/local --with-mpc=/opt/local --with-isl=/opt/local
--enable-stage1-checking --disable-multilib --enable-lto
--enable-libstdcxx-time --with-as=/opt/local/bin/as --with-ld=/opt/local/bin/ld
--with-ar=/opt/local/bin/ar --with-bugurl=https://trac.macports.org/newticket
--with-pkgversion='MacPorts gcc5 5.1.0_1'
Thread model: posix
gcc version 5.1.0 (MacPorts gcc5 5.1.0_1)


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/66615] Ambiguous conversion operators, explicit conversion operator and copy-initialization
  2015-06-21 13:24 [Bug c++/66615] New: Ambiguous conversion operators, explicit unambiguous conversion operator and copy initialization fynjycfdby at gmail dot com
@ 2015-06-21 14:14 ` trippels at gcc dot gnu.org
  2021-08-09 20:04 ` pinskia at gcc dot gnu.org
  2021-08-13 22:59 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: trippels at gcc dot gnu.org @ 2015-06-21 14:14 UTC (permalink / raw)
  To: gcc-bugs

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

Markus Trippelsdorf <trippels at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |accepts-invalid
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2015-06-21
                 CC|                            |trippels at gcc dot gnu.org
     Ever confirmed|0                           |1
      Known to fail|                            |4.9.2, 5.0, 6.0


^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/66615] Ambiguous conversion operators, explicit conversion operator and copy-initialization
  2015-06-21 13:24 [Bug c++/66615] New: Ambiguous conversion operators, explicit unambiguous conversion operator and copy initialization fynjycfdby at gmail dot com
  2015-06-21 14:14 ` [Bug c++/66615] Ambiguous conversion operators, explicit conversion operator and copy-initialization trippels at gcc dot gnu.org
@ 2021-08-09 20:04 ` pinskia at gcc dot gnu.org
  2021-08-13 22:59 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-09 20:04 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=77563
         Resolution|---                         |FIXED
             Status|NEW                         |RESOLVED

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 6.4.0 and 7.1.0.  Seems either a dup or closely related to bug
77563.

^ permalink raw reply	[flat|nested] 4+ messages in thread

* [Bug c++/66615] Ambiguous conversion operators, explicit conversion operator and copy-initialization
  2015-06-21 13:24 [Bug c++/66615] New: Ambiguous conversion operators, explicit unambiguous conversion operator and copy initialization fynjycfdby at gmail dot com
  2015-06-21 14:14 ` [Bug c++/66615] Ambiguous conversion operators, explicit conversion operator and copy-initialization trippels at gcc dot gnu.org
  2021-08-09 20:04 ` pinskia at gcc dot gnu.org
@ 2021-08-13 22:59 ` pinskia at gcc dot gnu.org
  2 siblings, 0 replies; 4+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-13 22:59 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |6.4

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2021-08-13 22:59 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-21 13:24 [Bug c++/66615] New: Ambiguous conversion operators, explicit unambiguous conversion operator and copy initialization fynjycfdby at gmail dot com
2015-06-21 14:14 ` [Bug c++/66615] Ambiguous conversion operators, explicit conversion operator and copy-initialization trippels at gcc dot gnu.org
2021-08-09 20:04 ` pinskia at gcc dot gnu.org
2021-08-13 22:59 ` pinskia at gcc dot gnu.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).