public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/57323] New: Overloaded && operator evaluates operands in the wrong order
@ 2013-05-18 15:45 calli911 at web dot de
  2013-05-18 15:48 ` [Bug c++/57323] " calli911 at web dot de
  2013-05-18 16:01 ` pinskia at gcc dot gnu.org
  0 siblings, 2 replies; 3+ messages in thread
From: calli911 at web dot de @ 2013-05-18 15:45 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57323

            Bug ID: 57323
           Summary: Overloaded && operator evaluates operands in the wrong
                    order
           Product: gcc
           Version: 4.7.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: calli911 at web dot de

Created attachment 30143
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30143&action=edit
The preprocessed source file.

The overloaded logical AND operator "&&" evaluates its operands in the wrong
order. In the following code example the operator behaves differently when used
with objects of a class than it does when using it with integers.

int main()
{
    Class x1(11);
    Class x2(22);

    int y1 = 11;
    int y2 = 22;

    f1(x1) && 0 && f2(x2);

    g1(y1) && 0 && g2(y2);

    return 0;
}

The function f2 gets called before f1 although it should not get called because
g2 does not get called either.

Executed command: g++ -v -save-temps bug.cpp

Output:

Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/i486-linux-gnu/4.7/lto-wrapper
Target: i486-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Debian 4.7.2-5'
--with-bugurl=file:///usr/share/doc/gcc-4.7/README.Bugs
--enable-languages=c,c++,go,fortran,objc,obj-c++ --prefix=/usr
--program-suffix=-4.7 --enable-shared --enable-linker-build-id
--with-system-zlib --libexecdir=/usr/lib --without-included-gettext
--enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.7
--libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu
--enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object
--enable-plugin --enable-objc-gc --enable-targets=all --with-arch-32=i586
--with-tune=generic --enable-checking=release --build=i486-linux-gnu
--host=i486-linux-gnu --target=i486-linux-gnu
Thread model: posix
gcc version 4.7.2 (Debian 4.7.2-5) 
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=i586'
 /usr/lib/gcc/i486-linux-gnu/4.7/cc1plus -E -quiet -v -imultiarch
i386-linux-gnu -D_GNU_SOURCE bug.cpp -mtune=generic -march=i586
-fpch-preprocess -o bug.ii
ignoring nonexistent directory "/usr/local/include/i386-linux-gnu"
ignoring nonexistent directory
"/usr/lib/gcc/i486-linux-gnu/4.7/../../../../i486-linux-gnu/include"
#include "..." search starts here:
#include <...> search starts here:
 /usr/include/c++/4.7
 /usr/include/c++/4.7/i486-linux-gnu
 /usr/include/c++/4.7/backward
 /usr/lib/gcc/i486-linux-gnu/4.7/include
 /usr/local/include
 /usr/lib/gcc/i486-linux-gnu/4.7/include-fixed
 /usr/include/i386-linux-gnu
 /usr/include
End of search list.
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=i586'
 /usr/lib/gcc/i486-linux-gnu/4.7/cc1plus -fpreprocessed bug.ii -quiet -dumpbase
bug.cpp -mtune=generic -march=i586 -auxbase bug -version -o bug.s
GNU C++ (Debian 4.7.2-5) version 4.7.2 (i486-linux-gnu)
    compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.1.0-p10,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
GNU C++ (Debian 4.7.2-5) version 4.7.2 (i486-linux-gnu)
    compiled by GNU C version 4.7.2, GMP version 5.0.5, MPFR version 3.1.0-p10,
MPC version 0.9
GGC heuristics: --param ggc-min-expand=100 --param ggc-min-heapsize=131072
Compiler executable checksum: 62bfd556e00a93e3d7f66f6876d73826
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=i586'
 as -v --32 -o bug.o bug.s
GNU assembler version 2.22 (i486-linux-gnu) using BFD version (GNU Binutils for
Debian) 2.22
COMPILER_PATH=/usr/lib/gcc/i486-linux-gnu/4.7/:/usr/lib/gcc/i486-linux-gnu/4.7/:/usr/lib/gcc/i486-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.7/:/usr/lib/gcc/i486-linux-gnu/
LIBRARY_PATH=/usr/lib/gcc/i486-linux-gnu/4.7/:/usr/lib/gcc/i486-linux-gnu/4.7/../../../i386-linux-gnu/:/usr/lib/gcc/i486-linux-gnu/4.7/../../../../lib/:/lib/i386-linux-gnu/:/lib/../lib/:/usr/lib/i386-linux-gnu/:/usr/lib/../lib/:/usr/lib/gcc/i486-linux-gnu/4.7/../../../:/lib/:/usr/lib/
COLLECT_GCC_OPTIONS='-v' '-save-temps' '-shared-libgcc' '-mtune=generic'
'-march=i586'
 /usr/lib/gcc/i486-linux-gnu/4.7/collect2 --sysroot=/ --build-id
--no-add-needed --eh-frame-hdr -m elf_i386 --hash-style=both -dynamic-linker
/lib/ld-linux.so.2
/usr/lib/gcc/i486-linux-gnu/4.7/../../../i386-linux-gnu/crt1.o
/usr/lib/gcc/i486-linux-gnu/4.7/../../../i386-linux-gnu/crti.o
/usr/lib/gcc/i486-linux-gnu/4.7/crtbegin.o -L/usr/lib/gcc/i486-linux-gnu/4.7
-L/usr/lib/gcc/i486-linux-gnu/4.7/../../../i386-linux-gnu
-L/usr/lib/gcc/i486-linux-gnu/4.7/../../../../lib -L/lib/i386-linux-gnu
-L/lib/../lib -L/usr/lib/i386-linux-gnu -L/usr/lib/../lib
-L/usr/lib/gcc/i486-linux-gnu/4.7/../../.. bug.o -lstdc++ -lm -lgcc_s -lgcc -lc
-lgcc_s -lgcc /usr/lib/gcc/i486-linux-gnu/4.7/crtend.o
/usr/lib/gcc/i486-linux-gnu/4.7/../../../i386-linux-gnu/crtn.o


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

* [Bug c++/57323] Overloaded && operator evaluates operands in the wrong order
  2013-05-18 15:45 [Bug c++/57323] New: Overloaded && operator evaluates operands in the wrong order calli911 at web dot de
@ 2013-05-18 15:48 ` calli911 at web dot de
  2013-05-18 16:01 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: calli911 at web dot de @ 2013-05-18 15:48 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57323

--- Comment #1 from calli911 at web dot de ---
Created attachment 30144
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=30144&action=edit
The output of the command.


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

* [Bug c++/57323] Overloaded && operator evaluates operands in the wrong order
  2013-05-18 15:45 [Bug c++/57323] New: Overloaded && operator evaluates operands in the wrong order calli911 at web dot de
  2013-05-18 15:48 ` [Bug c++/57323] " calli911 at web dot de
@ 2013-05-18 16:01 ` pinskia at gcc dot gnu.org
  1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu.org @ 2013-05-18 16:01 UTC (permalink / raw)
  To: gcc-bugs

http://gcc.gnu.org/bugzilla/show_bug.cgi?id=57323

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |INVALID

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
You are wrong.  When you overload operator &&, you cause the order of execution
of the two sides to become unspecified just like any function call arguments or
any non-short-cut operation in C++.


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

end of thread, other threads:[~2013-05-18 16:01 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-05-18 15:45 [Bug c++/57323] New: Overloaded && operator evaluates operands in the wrong order calli911 at web dot de
2013-05-18 15:48 ` [Bug c++/57323] " calli911 at web dot de
2013-05-18 16:01 ` 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).