public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/59329] New: Using `assert(...)` is not allowed in constexpr functions
@ 2013-11-28 11:17 vittorio.romeo at outlook dot com
  2013-12-02 14:04 ` [Bug c++/59329] " daniel.kruegler at googlemail dot com
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: vittorio.romeo at outlook dot com @ 2013-11-28 11:17 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 59329
           Summary: Using `assert(...)` is not allowed in constexpr
                    functions
           Product: gcc
           Version: 4.8.2
            Status: UNCONFIRMED
          Severity: trivial
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vittorio.romeo at outlook dot com

inline constexpr int exampleFunction(int min, int max)
{
    assert(min <= max);
    return min + max;
}

The above function fails to compile, because of the `assert(min <= max)`. 

g++ reports that a constexpr function may only be composed of a simple return
statement.

clang++ compiles the function successfully.



Is it possible to lift this restriction?


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

* [Bug c++/59329] Using `assert(...)` is not allowed in constexpr functions
  2013-11-28 11:17 [Bug c++/59329] New: Using `assert(...)` is not allowed in constexpr functions vittorio.romeo at outlook dot com
@ 2013-12-02 14:04 ` daniel.kruegler at googlemail dot com
  2014-01-23 17:13 ` lucdanton at free dot fr
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: daniel.kruegler at googlemail dot com @ 2013-12-02 14:04 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

--- Comment #1 from Daniel Krügler <daniel.kruegler at googlemail dot com> ---
At least it should be supported in c++1y mode, where several constexpr
restrictions had been lifted by the core language (but it currently isn't, not
even in the 4.9.0 trunk).
>From gcc-bugs-return-436422-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Mon Dec 02 14:52:53 2013
Return-Path: <gcc-bugs-return-436422-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 27698 invoked by alias); 2 Dec 2013 14:52:52 -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 27651 invoked by uid 48); 2 Dec 2013 14:52:46 -0000
From: "gjl at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug target/59174] [avr] Suboptimal multiplication when indexing an array
Date: Mon, 02 Dec 2013 14:52:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: target
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: gjl at gcc dot gnu.org
X-Bugzilla-Status: NEW
X-Bugzilla-Priority: P4
X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org
X-Bugzilla-Target-Milestone: ---
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields: cf_gcctarget priority bug_status cf_reconfirmed_on cc everconfirmed
Message-ID: <bug-59174-4-FCLGN0AODM@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-59174-4@http.gcc.gnu.org/bugzilla/>
References: <bug-59174-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-12/txt/msg00077.txt.bz2
Content-length: 1220

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

Georg-Johann Lay <gjl at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |avr
           Priority|P3                          |P4
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2013-12-02
                 CC|                            |gjl at gcc dot gnu.org
     Ever confirmed|0                           |1

--- Comment #1 from Georg-Johann Lay <gjl at gcc dot gnu.org> ---
Confirmed with the trunk.

This is an issue of cost computation in the avr backend.

If you compile with -O2 -mmcu=atmega2560 -mlog=rtx_costs you will see



avr_rtx_costs[test:combine(206)]=true (speed) total6, outer=set:
(mult:HI (reg:HI 47 [ D.1460 ])
    (const_int 10 [0xa]))

...

avr_rtx_costs[test:combine(206)]=true (speed) total2, outer=set:
(plus:HI (ashift:HI (reg:HI 47 [ D.1460 ])
        (const_int 3 [0x3]))
    (ashift:HI (reg:HI 47 [ D.1460 ])
        (const_int 1 [0x1])))


thus the MULT variant is taken as more costly that the ASHIFT + PLUS version.


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

* [Bug c++/59329] Using `assert(...)` is not allowed in constexpr functions
  2013-11-28 11:17 [Bug c++/59329] New: Using `assert(...)` is not allowed in constexpr functions vittorio.romeo at outlook dot com
  2013-12-02 14:04 ` [Bug c++/59329] " daniel.kruegler at googlemail dot com
@ 2014-01-23 17:13 ` lucdanton at free dot fr
  2014-05-08 21:18 ` jason at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: lucdanton at free dot fr @ 2014-01-23 17:13 UTC (permalink / raw)
  To: gcc-bugs

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

lucdanton at free dot fr changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |lucdanton at free dot fr

--- Comment #2 from lucdanton at free dot fr ---
As a workaround I thought about (ab)using the comma operator:

    return assert( cond ), expr;

The reasoning being that C guarantees that assert(…) is a void expression
(regardless of NDEBUG). This is rejected as well, although I’m not entirely
sure why. After a quick look at the preprocessed source, it appears GCC rejects
(‘body not a return statement’, again) functions of the form:

//------

void some_extern_func();

constexpr int foo(int i)
{ return (true ? static_cast<void>(0) : some_extern_func()), i; }

//-----

If the third leg of the conditional operator is e.g. throw whatever (a common
trick to ‘halt’ CTFE) everything behaves as expected.

Does this warrant opening another bug?
>From gcc-bugs-return-441337-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org Thu Jan 23 17:18:12 2014
Return-Path: <gcc-bugs-return-441337-listarch-gcc-bugs=gcc.gnu.org@gcc.gnu.org>
Delivered-To: listarch-gcc-bugs@gcc.gnu.org
Received: (qmail 7164 invoked by alias); 23 Jan 2014 17:18:11 -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 6869 invoked by uid 55); 23 Jan 2014 17:17:39 -0000
From: "redi at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug libstdc++/59872] [4.9 Regression] Cannot move std::map with move-only mapped_type
Date: Thu, 23 Jan 2014 17:18:00 -0000
X-Bugzilla-Reason: CC
X-Bugzilla-Type: changed
X-Bugzilla-Watch-Reason: None
X-Bugzilla-Product: gcc
X-Bugzilla-Component: libstdc++
X-Bugzilla-Version: 4.9.0
X-Bugzilla-Keywords:
X-Bugzilla-Severity: normal
X-Bugzilla-Who: redi at gcc dot gnu.org
X-Bugzilla-Status: ASSIGNED
X-Bugzilla-Priority: P3
X-Bugzilla-Assigned-To: redi at gcc dot gnu.org
X-Bugzilla-Target-Milestone: 4.9.0
X-Bugzilla-Flags:
X-Bugzilla-Changed-Fields:
Message-ID: <bug-59872-4-VRdh7SJyvN@http.gcc.gnu.org/bugzilla/>
In-Reply-To: <bug-59872-4@http.gcc.gnu.org/bugzilla/>
References: <bug-59872-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: 2014-01/txt/msg02479.txt.bz2
Content-length: 1368

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

--- Comment #9 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Author: redi
Date: Thu Jan 23 17:17:04 2014
New Revision: 206994

URL: http://gcc.gnu.org/viewcvs?rev 6994&root=gcc&view=rev
Log:
    PR libstdc++/59872
    * include/bits/stl_map.h (map::operator=(map&&)): Fix comment.
    * include/bits/stl_multimap.h (multimap::operator=(multimap&&)):
    Likewise.
    * include/bits/stl_multiset.h (multiset::operator=(multiset&&)):
    Likewise.
    * include/bits/stl_set.h (set::operator=(set&&)): Likewise.
    * include/bits/stl_tree.h (_Rb_tree::_M_move_data): New overloaded
    functions to perform moving or copying of elements from rvalue tree.
    (_Rb_tree::_Rb_tree(_Rb_tree&&)): Use _M_move_data.
    (_Rb_tree::_Rb_tree(_Rb_tree&&, _Node_allocator&&)): Likewise.
    * testsuite/23_containers/map/59872.cc: New.
    * testsuite/23_containers/map/56613.cc: Remove duplicate include.

Added:
    trunk/libstdc++-v3/testsuite/23_containers/map/59872.cc
Modified:
    trunk/libstdc++-v3/ChangeLog
    trunk/libstdc++-v3/include/bits/stl_map.h
    trunk/libstdc++-v3/include/bits/stl_multimap.h
    trunk/libstdc++-v3/include/bits/stl_multiset.h
    trunk/libstdc++-v3/include/bits/stl_set.h
    trunk/libstdc++-v3/include/bits/stl_tree.h
    trunk/libstdc++-v3/testsuite/23_containers/map/56613.cc


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

* [Bug c++/59329] Using `assert(...)` is not allowed in constexpr functions
  2013-11-28 11:17 [Bug c++/59329] New: Using `assert(...)` is not allowed in constexpr functions vittorio.romeo at outlook dot com
  2013-12-02 14:04 ` [Bug c++/59329] " daniel.kruegler at googlemail dot com
  2014-01-23 17:13 ` lucdanton at free dot fr
@ 2014-05-08 21:18 ` jason at gcc dot gnu.org
  2015-03-27 17:36 ` paolo.carlini at oracle dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: jason at gcc dot gnu.org @ 2014-05-08 21:18 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jason at gcc dot gnu.org
           Severity|trivial                     |enhancement

--- Comment #3 from Jason Merrill <jason at gcc dot gnu.org> ---
G++ doesn't implement the C++14 constexpr improvements yet.


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

* [Bug c++/59329] Using `assert(...)` is not allowed in constexpr functions
  2013-11-28 11:17 [Bug c++/59329] New: Using `assert(...)` is not allowed in constexpr functions vittorio.romeo at outlook dot com
                   ` (2 preceding siblings ...)
  2014-05-08 21:18 ` jason at gcc dot gnu.org
@ 2015-03-27 17:36 ` paolo.carlini at oracle dot com
  2015-03-27 17:40 ` paolo at gcc dot gnu.org
  2015-03-27 17:41 ` paolo.carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-27 17:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Paolo Carlini <paolo.carlini at oracle dot com> ---
This works in mainline. I'm adding the testcase and closing the bug.


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

* [Bug c++/59329] Using `assert(...)` is not allowed in constexpr functions
  2013-11-28 11:17 [Bug c++/59329] New: Using `assert(...)` is not allowed in constexpr functions vittorio.romeo at outlook dot com
                   ` (3 preceding siblings ...)
  2015-03-27 17:36 ` paolo.carlini at oracle dot com
@ 2015-03-27 17:40 ` paolo at gcc dot gnu.org
  2015-03-27 17:41 ` paolo.carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: paolo at gcc dot gnu.org @ 2015-03-27 17:40 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from paolo at gcc dot gnu.org <paolo at gcc dot gnu.org> ---
Author: paolo
Date: Fri Mar 27 17:21:32 2015
New Revision: 221740

URL: https://gcc.gnu.org/viewcvs?rev=221740&root=gcc&view=rev
Log:
2015-03-27  Paolo Carlini  <paolo.carlini@oracle.com>

    PR c++/59329
    * g++.dg/cpp1y/constexpr-assert1.C: New.

Added:
    trunk/gcc/testsuite/g++.dg/cpp1y/constexpr-assert1.C
Modified:
    trunk/gcc/testsuite/ChangeLog


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

* [Bug c++/59329] Using `assert(...)` is not allowed in constexpr functions
  2013-11-28 11:17 [Bug c++/59329] New: Using `assert(...)` is not allowed in constexpr functions vittorio.romeo at outlook dot com
                   ` (4 preceding siblings ...)
  2015-03-27 17:40 ` paolo at gcc dot gnu.org
@ 2015-03-27 17:41 ` paolo.carlini at oracle dot com
  5 siblings, 0 replies; 7+ messages in thread
From: paolo.carlini at oracle dot com @ 2015-03-27 17:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|---                         |FIXED
   Target Milestone|---                         |5.0

--- Comment #6 from Paolo Carlini <paolo.carlini at oracle dot com> ---
Done.


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

end of thread, other threads:[~2015-03-27 17:24 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-28 11:17 [Bug c++/59329] New: Using `assert(...)` is not allowed in constexpr functions vittorio.romeo at outlook dot com
2013-12-02 14:04 ` [Bug c++/59329] " daniel.kruegler at googlemail dot com
2014-01-23 17:13 ` lucdanton at free dot fr
2014-05-08 21:18 ` jason at gcc dot gnu.org
2015-03-27 17:36 ` paolo.carlini at oracle dot com
2015-03-27 17:40 ` paolo at gcc dot gnu.org
2015-03-27 17:41 ` paolo.carlini at oracle 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).