Giter Site home page Giter Site logo

Constexpr in facade.hpp about blackhole HOT 6 CLOSED

minaevmike avatar minaevmike commented on August 24, 2024
Constexpr in facade.hpp

from blackhole.

Comments (6)

3Hren avatar 3Hren commented on August 24, 2024

It can. It's GCC 5.3 bug.

from blackhole.

minaevmike avatar minaevmike commented on August 24, 2024

i use gcc 5.4

from blackhole.

3Hren avatar 3Hren commented on August 24, 2024

Well, that means that both GCC 5.3 and 5.4 are shit :)

> cat prog.cc
#include <stdexcept>

constexpr int f(int n) {
    if (n <= 0) throw std::runtime_error("");
    return 1;
}

int main() {
    constexpr auto val = f(42);   
}

Using GCC 5.3:

> g++ prog.cc -Wall -Wextra -std=gnu++1z

prog.cc: In function 'constexpr int f(int)':
prog.cc:6:1: error: expression '<throw-expression>' is not a constant-expression
 }
 ^
prog.cc: In function 'int main()':
prog.cc:9:27: error: 'constexpr int f(int)' called in a constant expression
     constexpr auto val = f(42);   
                           ^
prog.cc:9:20: warning: unused variable 'val' [-Wunused-variable]
     constexpr auto val = f(42);   
                    ^

Using both clang and GCC 6.0 (and trunk):

> g++ prog.cc -Wall -Wextra -std=gnu++1z

prog.cc: In function 'int main()':
prog.cc:9:20: warning: unused variable 'val' [-Wunused-variable]
     constexpr auto val = f(42);
                    ^~~

You may send a PR, but I don't see the correct way to resolve this issue.

There are compiler-defined macro variable that are used to check whether relaxed constexpr are supported by the compiler. Here they are:

#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304

GCC 5.3 defines them, but the implementation is terrible, leading to such kind of errors.

See http://stackoverflow.com/questions/34280729/throw-in-constexpr-function also.

from blackhole.

3Hren avatar 3Hren commented on August 24, 2024

I can suppress all constexpr magic for GCC 5.*

Please create a test, which compiles on trunk compilers, but fails to compile on GCC 5.*

from blackhole.

minaevmike avatar minaevmike commented on August 24, 2024

i am not sure is it a good fix or not, but locally i change

#if defined(__cpp_constexpr) && __cpp_constexpr >= 201304

to

#if (__GNUC__ >= 6 || defined(__clang__)) && defined(__cpp_constexpr) && __cpp_constexpr >= 201304

from blackhole.

3Hren avatar 3Hren commented on August 24, 2024

It's totally ok. Historically it's impossible to build with GCC without hacking with #ifdef.

from blackhole.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.