Bug 58255 - [C++11] explicit delegating constructor with no arguments wrongly rejected
Summary: [C++11] explicit delegating constructor with no arguments wrongly rejected
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: unknown
: P3 normal
Target Milestone: 4.9.0
Assignee: Paolo Carlini
URL:
Keywords: rejects-valid
Depends on:
Blocks:
 
Reported: 2013-08-28 00:25 UTC by Paul Pluzhnikov
Modified: 2013-08-28 22:41 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2013-08-28 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Paul Pluzhnikov 2013-08-28 00:25:02 UTC
Google ref: b/10458361

Test:

struct A {
  explicit A() { }   // remove explicit -> compiles fine
  A(int x) : A() { }
};


Builds with Clang.
Fails using g++ (GCC) 4.9.0 20130827 (experimental):


g++ -c -std=c++11  /tmp/t1.cc -o /tmp/t.o
/tmp/t1.cc: In constructor 'A::A(int)':
/tmp/t1.cc:3:16: error: no matching function for call to 'A::A()'
   A(int x) : A() { }
                ^
/tmp/t1.cc:3:16: note: candidates are:
/tmp/t1.cc:3:3: note: A::A(int)
   A(int x) : A() { }
   ^
/tmp/t1.cc:3:3: note:   candidate expects 1 argument, 0 provided
/tmp/t1.cc:1:8: note: constexpr A::A(const A&)
 struct A {
        ^
/tmp/t1.cc:1:8: note:   candidate expects 1 argument, 0 provided
/tmp/t1.cc:1:8: note: constexpr A::A(A&&)
/tmp/t1.cc:1:8: note:   candidate expects 1 argument, 0 provided


This has been broken since at least gcc-4.7
Comment 1 Paolo Carlini 2013-08-28 11:06:28 UTC
Seems easy.
Comment 2 Paolo Carlini 2013-08-28 11:28:44 UTC
I'm finishing testing this:

Index: init.c
===================================================================
--- init.c	(revision 202020)
+++ init.c	(working copy)
@@ -1465,6 +1465,7 @@ build_aggr_init (tree exp, tree init, int flags, t
   TREE_THIS_VOLATILE (exp) = 0;
 
   if (init && TREE_CODE (init) != TREE_LIST
+      && init != void_type_node
       && !(TREE_CODE (init) == TARGET_EXPR
 	   && TARGET_EXPR_DIRECT_INIT_P (init))
       && !(BRACE_ENCLOSED_INITIALIZER_P (init)
Comment 3 paolo@gcc.gnu.org 2013-08-28 22:40:36 UTC
Author: paolo
Date: Wed Aug 28 22:40:34 2013
New Revision: 202061

URL: http://gcc.gnu.org/viewcvs?rev=202061&root=gcc&view=rev
Log:
/cp
2013-08-28  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/58255
	* init.c (build_aggr_init): When init == void_type_node do not
	set LOOKUP_ONLYCONVERTING.

/testsuite
2013-08-28  Paolo Carlini  <paolo.carlini@oracle.com>

	PR c++/58255
	* g++.dg/cpp0x/dc7.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/dc7.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/init.c
    trunk/gcc/testsuite/ChangeLog
Comment 4 Paolo Carlini 2013-08-28 22:41:12 UTC
Fixed for 4.9.0.