public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/51424] New: [C++11] G++ should diagnose self-delegating constructors
@ 2011-12-05 16:10 jason at gcc dot gnu.org
  2013-08-29 12:54 ` [Bug c++/51424] " paolo.carlini at oracle dot com
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: jason at gcc dot gnu.org @ 2011-12-05 16:10 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51424
           Summary: [C++11] G++ should diagnose self-delegating
                    constructors
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Keywords: diagnostic
          Severity: normal
          Priority: P3
         Component: c++
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: jason@gcc.gnu.org
                CC: pedro.lamarao@gmail.com, ville.voutilainen@gmail.com


This modification of g++.dg/template/meminit1.C should get a diagnostic in
C++11 mode as well:

template <class T >
struct S
{
  S() : S() {} // { dg-message "delegating constructors" "" { target c++98 } }
  // { dg-error "delegates to itself" "" { target c++11 } }
};

S<int> s;

because 12.6.2 says,

"If a constructor delegates to itself directly or indirectly, the program is
ill-formed; no diagnostic is required."

The diagnostic is not required, but it is easy to give, so we should do so.


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

* [Bug c++/51424] [C++11] G++ should diagnose self-delegating constructors
  2011-12-05 16:10 [Bug c++/51424] New: [C++11] G++ should diagnose self-delegating constructors jason at gcc dot gnu.org
@ 2013-08-29 12:54 ` paolo.carlini at oracle dot com
  2013-08-30 15:39 ` paolo at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2013-08-29 12:54 UTC (permalink / raw)
  To: gcc-bugs

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

Paolo Carlini <paolo.carlini at oracle dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |ASSIGNED
   Last reconfirmed|                            |2013-08-29
           Assignee|unassigned at gcc dot gnu.org      |paolo.carlini at oracle dot com
   Target Milestone|---                         |4.9.0
     Ever confirmed|0                           |1

--- Comment #2 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I have a very simple patch which appears to work fine (for the very simple
cases ;) but constexpr constructors, virtual inheritance, etc are included)

Index: init.c
===================================================================
--- init.c    (revision 202070)
+++ init.c    (working copy)
@@ -500,8 +500,9 @@ perform_target_ctor (tree init)
   tree decl = current_class_ref;
   tree type = current_class_type;

-  finish_expr_stmt (build_aggr_init (decl, init, LOOKUP_NORMAL,
-                                     tf_warning_or_error));
+  finish_expr_stmt (build_aggr_init (decl, init,
+                     LOOKUP_NORMAL|LOOKUP_DELEGATING_CONS,
+                     tf_warning_or_error));
   if (TYPE_HAS_NONTRIVIAL_DESTRUCTOR (type))
     {
       tree expr = build_delete (type, decl, sfk_complete_destructor,
@@ -1667,6 +1668,13 @@ expand_default_init (tree binfo, tree true_exp, tr
   if (parms != NULL)
     release_tree_vector (parms);

+  if ((complain & tf_error)
+      && (flags & LOOKUP_DELEGATING_CONS)
+      && TREE_CODE (rval) == CALL_EXPR
+      && (DECL_ABSTRACT_ORIGIN (TREE_OPERAND (CALL_EXPR_FN (rval), 0))
+      == current_function_decl))
+    error ("constructor delegates to itself");
+
   if (exp == true_exp && TREE_CODE (rval) == CALL_EXPR)
     {
       tree fn = get_callee_fndecl (rval);
Index: cp-tree.h
===================================================================
--- cp-tree.h    (revision 202070)
+++ cp-tree.h    (working copy)
@@ -4509,6 +4509,8 @@ enum overload_flags { NO_SPECIAL = 0, DTOR_FLAG, T
 #define LOOKUP_NO_RVAL_BIND (LOOKUP_EXPLICIT_TMPL_ARGS << 1)
 /* Used by case_conversion to disregard non-integral conversions.  */
 #define LOOKUP_NO_NON_INTEGRAL (LOOKUP_NO_RVAL_BIND << 1)
+/* Used for delegating constructors in order to diagnose self-delegation.  */
+#define LOOKUP_DELEGATING_CONS (LOOKUP_NO_NON_INTEGRAL << 1)

 #define LOOKUP_NAMESPACES_ONLY(F)  \
   (((F) & LOOKUP_PREFER_NAMESPACES) && !((F) & LOOKUP_PREFER_TYPES))


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

* [Bug c++/51424] [C++11] G++ should diagnose self-delegating constructors
  2011-12-05 16:10 [Bug c++/51424] New: [C++11] G++ should diagnose self-delegating constructors jason at gcc dot gnu.org
  2013-08-29 12:54 ` [Bug c++/51424] " paolo.carlini at oracle dot com
@ 2013-08-30 15:39 ` paolo at gcc dot gnu.org
  2014-04-22 11:38 ` jakub at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: paolo at gcc dot gnu.org @ 2013-08-30 15:39 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Fri Aug 30 15:39:01 2013
New Revision: 202110

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

    PR c++/51424
    * cp-tree.h (LOOKUP_DELEGATING_CONS): Add.
    * init.c (perform_target_ctor): Use it.
    * call.c (build_special_member_call): Diagnose self-delegating
    constructors.

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

    PR c++/51424
    * g++.dg/cpp0x/dc8.C: New.
    * g++.dg/template/meminit1.C: Adjust.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/dc8.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/call.c
    trunk/gcc/cp/cp-tree.h
    trunk/gcc/cp/init.c
    trunk/gcc/testsuite/ChangeLog
    trunk/gcc/testsuite/g++.dg/template/meminit1.C


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

* [Bug c++/51424] [C++11] G++ should diagnose self-delegating constructors
  2011-12-05 16:10 [Bug c++/51424] New: [C++11] G++ should diagnose self-delegating constructors jason at gcc dot gnu.org
  2013-08-29 12:54 ` [Bug c++/51424] " paolo.carlini at oracle dot com
  2013-08-30 15:39 ` paolo at gcc dot gnu.org
@ 2014-04-22 11:38 ` jakub at gcc dot gnu.org
  2014-04-22 12:03 ` ville.voutilainen at gmail dot com
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-04-22 11:38 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|4.9.0                       |4.9.1

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 4.9.0 has been released


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

* [Bug c++/51424] [C++11] G++ should diagnose self-delegating constructors
  2011-12-05 16:10 [Bug c++/51424] New: [C++11] G++ should diagnose self-delegating constructors jason at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2014-04-22 11:38 ` jakub at gcc dot gnu.org
@ 2014-04-22 12:03 ` ville.voutilainen at gmail dot com
  2014-04-22 12:53 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: ville.voutilainen at gmail dot com @ 2014-04-22 12:03 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
(In reply to Jakub Jelinek from comment #4)
> GCC 4.9.0 has been released

Well, shouldn't this bug be closed, then? The patch Paolo wrote was applied and
shipped in 4.9.0, so this is already in, no need to change the milestone to
4.9.1.


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

* [Bug c++/51424] [C++11] G++ should diagnose self-delegating constructors
  2011-12-05 16:10 [Bug c++/51424] New: [C++11] G++ should diagnose self-delegating constructors jason at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2014-04-22 12:03 ` ville.voutilainen at gmail dot com
@ 2014-04-22 12:53 ` jakub at gcc dot gnu.org
  2014-04-28  9:54 ` paolo.carlini at oracle dot com
  2014-04-28 10:33 ` ville.voutilainen at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: jakub at gcc dot gnu.org @ 2014-04-22 12:53 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
                 CC|                            |jakub at gcc dot gnu.org
         Resolution|---                         |FIXED
   Target Milestone|4.9.1                       |4.9.0

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
Then it should have been closed months ago.


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

* [Bug c++/51424] [C++11] G++ should diagnose self-delegating constructors
  2011-12-05 16:10 [Bug c++/51424] New: [C++11] G++ should diagnose self-delegating constructors jason at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2014-04-22 12:53 ` jakub at gcc dot gnu.org
@ 2014-04-28  9:54 ` paolo.carlini at oracle dot com
  2014-04-28 10:33 ` ville.voutilainen at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: paolo.carlini at oracle dot com @ 2014-04-28  9:54 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from Paolo Carlini <paolo.carlini at oracle dot com> ---
I seem to remember that the reason why I didn't close it completely at the time
is that we may want to extend the diagnostic to cover non-trivial cycles too...
Opinions? Could also be a separate bug, that for sure.


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

* [Bug c++/51424] [C++11] G++ should diagnose self-delegating constructors
  2011-12-05 16:10 [Bug c++/51424] New: [C++11] G++ should diagnose self-delegating constructors jason at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2014-04-28  9:54 ` paolo.carlini at oracle dot com
@ 2014-04-28 10:33 ` ville.voutilainen at gmail dot com
  6 siblings, 0 replies; 8+ messages in thread
From: ville.voutilainen at gmail dot com @ 2014-04-28 10:33 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from Ville Voutilainen <ville.voutilainen at gmail dot com> ---
My 2 cents is to open a separate bug if we want diagnostics for the more
elaborate self-delegating cases.


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

end of thread, other threads:[~2014-04-28 10:33 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-12-05 16:10 [Bug c++/51424] New: [C++11] G++ should diagnose self-delegating constructors jason at gcc dot gnu.org
2013-08-29 12:54 ` [Bug c++/51424] " paolo.carlini at oracle dot com
2013-08-30 15:39 ` paolo at gcc dot gnu.org
2014-04-22 11:38 ` jakub at gcc dot gnu.org
2014-04-22 12:03 ` ville.voutilainen at gmail dot com
2014-04-22 12:53 ` jakub at gcc dot gnu.org
2014-04-28  9:54 ` paolo.carlini at oracle dot com
2014-04-28 10:33 ` ville.voutilainen at gmail 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).