public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/66632] New: Incorrect use of default constructor to initialize isolated rvalue.
@ 2015-06-22 23:51 jasonxbell at gmail dot com
  2015-06-22 23:57 ` [Bug c++/66632] " jasonxbell at gmail dot com
  2015-06-23 18:14 ` daniel.kruegler at googlemail dot com
  0 siblings, 2 replies; 3+ messages in thread
From: jasonxbell at gmail dot com @ 2015-06-22 23:51 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 66632
           Summary: Incorrect use of default constructor to initialize
                    isolated rvalue.
           Product: gcc
           Version: 4.9.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jasonxbell at gmail dot com
  Target Milestone: ---

Created attachment 35828
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=35828&action=edit
Preprocessed source file

In the following code, the first statement in main() -- 'Q(S1v1)' -- creates an
isolated rvalue; g++ uses the default constructor to initialize it instead of
'Q::Q(S1 x)'. The lvalue q1 is then init'd via copy of the (incorrectly init'd)
rvalue from the previous statement.


bug2.c:
--------------------------------------------------------------------------------
#include <iostream>
using std::cout;
using std::ostream;

enum S1 { S1v0 = 0, S1v1= 10, S1v2, S1v3 };


class Q
{
public:
           Q()               : mySN(nextSN++), s1val(S1v0)      { cout << "+Q
#" << mySN << " Default\n"; }
           Q(const Q  &src ) : mySN(nextSN++), s1val(src.s1val) { cout << "+Q
#" << mySN << " Copy from #" << src.mySN << '\n'; }

  explicit Q(S1 x)           : mySN(nextSN++), s1val(x)         { cout << "+Q
#" << mySN << " from S1\n"; }

private:
  int mySN;
  S1 s1val;

  static int nextSN;

  friend ostream& operator<<( ostream &out, const Q &obj );

};

int Q::nextSN = 1;

ostream& operator<<( ostream &out, const Q &obj )
{
  out << "Q #" << obj.mySN << " == " << obj.s1val << '\n'; 
  return out;
}


int main( void )
{

  Q(S1v1);
  Q q2{S1v1};
  cout << '\n';

  cout << q2;

  return 0;
}
--------------------------------------------------------------------------------



Compile and run:

$ g++ -std=c++11 -pedantic -Wall -Wextra bug2.cpp; ./a.exe
+Q #1 Default
+Q #2 Copy from #1

Q #2 == 0


$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-cygwin/4.9.2/lto-wrapper.exe
Target: x86_64-pc-cygwin
Configured with:
/cygdrive/i/szsz/tmpp/gcc/gcc-4.9.2-3.x86_64/src/gcc-4.9.2/configure
--srcdir=/cygdrive/i/szsz/tmpp/gcc/gcc-4.9.2-3.x86_64/src/gcc-4.9.2
--prefix=/usr --exec-prefix=/usr --bindir=/usr/bin --sbindir=/usr/sbin
--libexecdir=/usr/libexec --datadir=/usr/share --localstatedir=/var
--sysconfdir=/etc --libdir=/usr/lib --datarootdir=/usr/share
--docdir=/usr/share/doc/gcc --htmldir=/usr/share/doc/gcc/html -C
--build=x86_64-pc-cygwin --host=x86_64-pc-cygwin --target=x86_64-pc-cygwin
--without-libiconv-prefix --without-libintl-prefix --libexecdir=/usr/lib
--enable-shared --enable-shared-libgcc --enable-static
--enable-version-specific-runtime-libs --enable-bootstrap --enable-__cxa_atexit
--with-dwarf2 --with-tune=generic
--enable-languages=ada,c,c++,fortran,lto,objc,obj-c++ --enable-graphite
--enable-threads=posix --enable-libatomic --enable-libgomp --disable-libitm
--enable-libquadmath --enable-libquadmath-support --enable-libssp
--enable-libada --enable-libgcj-sublibs --disable-java-awt --disable-symvers
--with-ecj-jar=/usr/share/java/ecj.jar --with-gnu-ld --with-gnu-as
--with-cloog-include=/usr/include/cloog-isl --without-libiconv-prefix
--without-libintl-prefix --with-system-zlib --enable-linker-build-id
Thread model: posix
gcc version 4.9.2 (GCC)


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

* [Bug c++/66632] Incorrect use of default constructor to initialize isolated rvalue.
  2015-06-22 23:51 [Bug c++/66632] New: Incorrect use of default constructor to initialize isolated rvalue jasonxbell at gmail dot com
@ 2015-06-22 23:57 ` jasonxbell at gmail dot com
  2015-06-23 18:14 ` daniel.kruegler at googlemail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: jasonxbell at gmail dot com @ 2015-06-22 23:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from jasonxbell at gmail dot com ---
Correction: In the sentence "The lvalue q1 is then init'd via copy of the
(incorrectly init'd) rvalue from the previous statement.", replace "q1" with
"q2".


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

* [Bug c++/66632] Incorrect use of default constructor to initialize isolated rvalue.
  2015-06-22 23:51 [Bug c++/66632] New: Incorrect use of default constructor to initialize isolated rvalue jasonxbell at gmail dot com
  2015-06-22 23:57 ` [Bug c++/66632] " jasonxbell at gmail dot com
@ 2015-06-23 18:14 ` daniel.kruegler at googlemail dot com
  1 sibling, 0 replies; 3+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2015-06-23 18:14 UTC (permalink / raw)
  To: gcc-bugs

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

Daniel Krügler <daniel.kruegler at googlemail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |daniel.kruegler@googlemail.
                   |                            |com

--- Comment #2 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
The program output looks correct to me. You are misinterpreting what the
semantics of the code is. The construct

Q(S1v1);

declares a variable of type Q with name S1v1, it therefore hides the enumerator
name in the next line. The next line just performs a copy of the variable S1v1
to produce the variable q2. In other words, this is not a defect.
>From gcc-bugs-return-489999-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Tue Jun 23 18:16:26 2015
Return-Path: <gcc-bugs-return-489999-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 5062 invoked by alias); 23 Jun 2015 18:16:26 -0000
Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm
Precedence: bulk
List-Id: <gcc-bugs.gcc.gnu.org>
List-Archive: <http://gcc.gnu.org/ml/gcc-bugs/>
List-Post: <mailto:gcc-bugs@gcc.gnu.org>
List-Help: <mailto:gcc-bugs-help@gcc.gnu.org>
Sender: gcc-bugs-owner@gcc.gnu.org
Delivered-To: mailing list gcc-bugs@gcc.gnu.org
Received: (qmail 5024 invoked by uid 48); 23 Jun 2015 18:16:22 -0000
From: "mpolacek at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug c++/66632] Incorrect use of default constructor to initialize isolated rvalue.
Date: Tue, 23 Jun 2015 18:16:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: c++
X-Bugzilla-Version: 4.9.2
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: mpolacek at gcc dot gnu.org
X-Bugzilla-Status: RESOLVED
X-Bugzilla-Resolution: INVALID
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: bug_status cc resolution
Message-ID: <bug-66632-4-2IJ8mYfmV1@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-66632-4@http.gcc.gnu.org/bugzilla/>
References: <bug-66632-4@http.gcc.gnu.org/bugzilla/>
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: 7bit
X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/
Auto-Submitted: auto-generated
MIME-Version: 1.0
X-SW-Source: 2015-06/txt/msg02331.txt.bz2
Content-length: 514

https://gcc.gnu.org/bugzilla/show_bug.cgi?idf632

Marek Polacek <mpolacek at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |mpolacek at gcc dot gnu.org
         Resolution|---                         |INVALID

--- Comment #3 from Marek Polacek <mpolacek at gcc dot gnu.org> ---
Thus invalid.


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

end of thread, other threads:[~2015-06-23 18:14 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-06-22 23:51 [Bug c++/66632] New: Incorrect use of default constructor to initialize isolated rvalue jasonxbell at gmail dot com
2015-06-22 23:57 ` [Bug c++/66632] " jasonxbell at gmail dot com
2015-06-23 18:14 ` daniel.kruegler at googlemail dot com

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).