public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/58162] New: [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)'
@ 2013-08-14 22:18 ppluzhnikov at google dot com
  2013-10-03  5:15 ` [Bug c++/58162] " james.dennett at gmail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: ppluzhnikov at google dot com @ 2013-08-14 22:18 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 58162
           Summary: [C++11] bogus error: use of deleted function
                    'constexpr A::A(const A&)'
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppluzhnikov at google dot com

Google ref b/10272620

/// --- cut ---
struct A {
 A();
 A(A&&);
};

struct B {
 A const a = A();
};

B b;
/// --- cut ---

Using trunk: g++ (GCC) 4.9.0 20130814 (experimental)

g++ -c -std=c++11 t.cc
t.cc: In constructor ‘constexpr B::B()’:
t.cc:6:8: error: use of deleted function ‘constexpr A::A(const A&)’
 struct B {
        ^
t.cc:1:8: note: ‘constexpr A::A(const A&)’ is implicitly declared as deleted
because ‘A’ declares a move constructor or move assignment operator
 struct A {
        ^
t.cc: At global scope:
t.cc:10:3: note: synthesized method ‘constexpr B::B()’ first required here 
 B b;
   ^


Analysys by jdennett

  This is under 8.5p17 (via other sections... 9.2[Class Members]p4 leads
  to 12.6.2, and 12.6.2p8 says "if the entity is a non-static data member
  that has a brace-or-equal-initializer, the entity is initialized as
  specified in 8.5"), and (I believe) should be the same initialization
  as for a local variable declared as

    A const a = A();

  (All references above are in the C++14 CD.)

  8.5p17 says:

  "If the destination type is a (possibly cv-qualified) class type:
  — If the initialization is direct-initialization, or if it is
  copy-initialization where the cv-unqualified version of the source type
  is the same class as, or a derived class of, the class of the destination,
  constructors are considered."

  We're in the case of copy-initialization where the cv-unqualified
  version of the source type is A, and the destination type is "const A",
  but arguably "the class of the destination" is A (because const A isn't
  a class).

  So I believe that this should fall into the same case as
  direct-initialization, overload resolution should pick the A::A(A&&)
  move constructor, and all should be good.

  Wild guesses about how this might go wrong in the compiler:

  It might be that G++ is checking whether the cv-unqualified version of
  the source type is the same as the destination type (rather than the same
  as the cv-unqualified version of the destination type, which is the class
  here).  If so, it would fall into the main case of copy-initialization,
  which creates a temporary of the target type.  That should still work,
  but if the temporary were (incorrectly) considered to be a "const A"
  rather than an "A" then initializing from it would attempt to use the
  (deleted) copy constructor.

  Seeing if changing A(A&&) to A(A const&&) changes anything might be
  informative, or having both overloads present.


Changing 'A(A&&);' to 'A(const AA&&);' or adding it as overload does fix
the compilation problem.

Further patch from jdennett:

With the following hack, the testcase compiles.

$ svn diff gcc
Index: gcc/cp/parser.c
===================================================================
--- gcc/cp/parser.c     (revision 201651)
+++ gcc/cp/parser.c     (working copy)
@@ -23002,7 +23002,10 @@
         if (BRACE_ENCLOSED_INITIALIZER_P (parsed_arg)
             && CONSTRUCTOR_IS_DIRECT_INIT (parsed_arg))
           flags = LOOKUP_NORMAL;
-         parsed_arg = digest_init_flags (TREE_TYPE (decl), parsed_arg, flags);
+         // TODO(jdennett): Something better than this, and work out how
+         // to test it.
+         parsed_arg = digest_init_flags (TYPE_MAIN_VARIANT (TREE_TYPE (decl)),
+                                         parsed_arg, flags);
       }
    }
>From gcc-bugs-return-427866-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Wed Aug 14 22:31:21 2013
Return-Path: <gcc-bugs-return-427866-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 15239 invoked by alias); 14 Aug 2013 22:31:21 -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 15221 invoked by uid 48); 14 Aug 2013 22:31:20 -0000
From: "ppluzhnikov at google dot com" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/58163] New: [C++11] Pedantic assert on str[str.size()] is wrong in C++11
Date: Wed, 14 Aug 2013 22:31:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: new
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: libstdc++
X-Bugzilla-Version: unknown
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: ppluzhnikov at google dot com
X-Bugzilla-Status: UNCONFIRMED
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_id short_desc product version bug_status bug_severity priority component assigned_to reporter
Message-ID: <bug-58163-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: 2013-08/txt/msg00790.txt.bz2
Content-length: 1985

http://gcc.gnu.org/bugzilla/show_bug.cgi?idX163

            Bug ID: 58163
           Summary: [C++11] Pedantic assert on str[str.size()] is wrong in
                    C++11
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: libstdc++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ppluzhnikov at google dot com

Google ref b/10322506

/// --- cut ---
#include <string>

int main()
{
  const std::string cs;
        std::string  s;

  if (cs[0] != '\0') return 1;
  if (s[0] != '\0') return 2;

  return 0;
}
/// --- cut ---

Using trunk gcc g++ (GCC) 4.9.0 20130814 (experimental)

g++ -g t.cc -D_GLIBCXX_DEBUG_PEDANTIC -D_GLIBCXX_DEBUG -std=c++11 && ./a.out
/gcc-svn-install/include/c++/4.9.0/bits/basic_string.h:848:
std::basic_string<_CharT, _Traits, _Alloc>::reference std::basic_string<_CharT,
_Traits, _Alloc>::operator[](std::basic_string<_CharT, _Traits,
_Alloc>::size_type) [with _CharT = char; _Traits = std::char_traits<char>;
_Alloc = std::allocator<char>; std::basic_string<_CharT, _Traits,
_Alloc>::reference = char&; std::basic_string<_CharT, _Traits,
_Alloc>::size_type = long unsigned int]: Assertion '__pos < size()' failed.

In C++98:

21.3.4 basic_string element access [lib.string.access]

const_reference operator[](size_type pos) const;
reference operator[](size_type pos);

Returns: If pos < size(), returns data()[pos]. Otherwise, if pos == size(),
the const version returns charT().

Otherwise, the behavior is undefined.  <<== PEDASSERT catches this.


However, in C++11:

21.4.5 basic_string element access [string.access]

const_reference operator[](size_type pos) const;
reference operator[](size_type pos);

Requires: pos <= size().

Returns: *(begin() + pos) if pos < size(), otherwise a reference to an object
of type T with value charT(); the referenced value shall not be modied.


Note removal of undefined behavior.


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

* [Bug c++/58162] [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)'
  2013-08-14 22:18 [Bug c++/58162] New: [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)' ppluzhnikov at google dot com
@ 2013-10-03  5:15 ` james.dennett at gmail dot com
  2013-10-31 14:42 ` jason at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: james.dennett at gmail dot com @ 2013-10-03  5:15 UTC (permalink / raw)
  To: gcc-bugs

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

James Dennett <james.dennett at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |james.dennett at gmail dot com

--- Comment #1 from James Dennett <james.dennett at gmail dot com> ---
Jason pointed out to me that cv_unqualified() is more appropriate than
TYPE_MAIN_VARIANT(), and I see that we might want to do the

 if (!CLASS_TYPE_P (type) && cv_qualified_p (type))
    type = cv_unqualified (type);

dance to avoid needless work for other types.


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

* [Bug c++/58162] [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)'
  2013-08-14 22:18 [Bug c++/58162] New: [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)' ppluzhnikov at google dot com
  2013-10-03  5:15 ` [Bug c++/58162] " james.dennett at gmail dot com
@ 2013-10-31 14:42 ` jason at gcc dot gnu.org
  2013-10-31 14:51 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2013-10-31 14:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Thu Oct 31 14:41:55 2013
New Revision: 204263

URL: http://gcc.gnu.org/viewcvs?rev=204263&root=gcc&view=rev
Log:
    PR c++/58162
    * parser.c (cp_parser_late_parse_one_default_arg): Set
    TARGET_EXPR_DIRECT_INIT_P.

Added:
    trunk/gcc/testsuite/g++.dg/cpp0x/nsdmi9.C
Modified:
    trunk/gcc/cp/ChangeLog
    trunk/gcc/cp/parser.c


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

* [Bug c++/58162] [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)'
  2013-08-14 22:18 [Bug c++/58162] New: [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)' ppluzhnikov at google dot com
  2013-10-03  5:15 ` [Bug c++/58162] " james.dennett at gmail dot com
  2013-10-31 14:42 ` jason at gcc dot gnu.org
@ 2013-10-31 14:51 ` jason at gcc dot gnu.org
  2013-10-31 17:37 ` james.dennett at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2013-10-31 14:51 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
                 CC|                            |jason at gcc dot gnu.org
         Resolution|---                         |FIXED
           Assignee|unassigned at gcc dot gnu.org      |jason at gcc dot gnu.org
   Target Milestone|---                         |4.9.0

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
Fixed for 4.9.


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

* [Bug c++/58162] [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)'
  2013-08-14 22:18 [Bug c++/58162] New: [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)' ppluzhnikov at google dot com
                   ` (2 preceding siblings ...)
  2013-10-31 14:51 ` jason at gcc dot gnu.org
@ 2013-10-31 17:37 ` james.dennett at gmail dot com
  2013-11-24  2:44 ` jason at gcc dot gnu.org
  2013-11-24  2:54 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: james.dennett at gmail dot com @ 2013-10-31 17:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from James Dennett <james.dennett at gmail dot com> ---
Thanks, Jason.


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

* [Bug c++/58162] [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)'
  2013-08-14 22:18 [Bug c++/58162] New: [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)' ppluzhnikov at google dot com
                   ` (3 preceding siblings ...)
  2013-10-31 17:37 ` james.dennett at gmail dot com
@ 2013-11-24  2:44 ` jason at gcc dot gnu.org
  2013-11-24  2:54 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2013-11-24  2:44 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
Author: jason
Date: Sun Nov 24 02:43:54 2013
New Revision: 205322

URL: http://gcc.gnu.org/viewcvs?rev=205322&root=gcc&view=rev
Log:
    PR c++/58162
    * parser.c (cp_parser_late_parse_one_default_arg): Set
    TARGET_EXPR_DIRECT_INIT_P.

Added:
    branches/gcc-4_8-branch/gcc/testsuite/g++.dg/cpp0x/nsdmi9.C
Modified:
    branches/gcc-4_8-branch/gcc/cp/ChangeLog
    branches/gcc-4_8-branch/gcc/cp/parser.c


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

* [Bug c++/58162] [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)'
  2013-08-14 22:18 [Bug c++/58162] New: [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)' ppluzhnikov at google dot com
                   ` (4 preceding siblings ...)
  2013-11-24  2:44 ` jason at gcc dot gnu.org
@ 2013-11-24  2:54 ` jason at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2013-11-24  2:54 UTC (permalink / raw)
  To: gcc-bugs

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

Jason Merrill <jason at gcc dot gnu.org> changed:

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


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

end of thread, other threads:[~2013-11-24  2:54 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-14 22:18 [Bug c++/58162] New: [C++11] bogus error: use of deleted function 'constexpr A::A(const A&)' ppluzhnikov at google dot com
2013-10-03  5:15 ` [Bug c++/58162] " james.dennett at gmail dot com
2013-10-31 14:42 ` jason at gcc dot gnu.org
2013-10-31 14:51 ` jason at gcc dot gnu.org
2013-10-31 17:37 ` james.dennett at gmail dot com
2013-11-24  2:44 ` jason at gcc dot gnu.org
2013-11-24  2:54 ` jason 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).