GithubHelp home page GithubHelp logo

The use of "return true ? <object> : <exception>" syntax in code about constexpr HOT 4 OPEN

adleret221 avatar adleret221 commented on August 11, 2024
The use of "return true ? : " syntax in code

from constexpr.

Comments (4)

LB-- avatar LB-- commented on August 11, 2024 1

Well there is P1073R0 that we might have some day.

from constexpr.

elbeno avatar elbeno commented on August 11, 2024

This is Scott Schurr's link-time hack that attempts to prevent accidental non-constexpr usage of a function. The idea is that if you accidentally call a function in a non-constexpr context, it will reference a symbol that is not defined and cause a link error. Notice that everything that is thrown is externed, but not defined anywhere.

This is definitely not portable, but it works (worked?) on some compilers. I hope in future there will be better ways to guard against non-constexpr usage. The constexpr parts of C++ are evolving fast at the moment, so this repo is a dated experiment at this point.

from constexpr.

DanielJump avatar DanielJump commented on August 11, 2024

Unfortunately, this doesn't work on MSVC anymore.
cx_sha256.h(24,26): error C7631: 'cx::err::`anonymous-namespace'::sha256_runtime_error': variable with internal linkage declared but not defined

It's also a warning on clang (-Wundefined-internal) but that can be disabled.

This thread has some ideas - could we use one of those instead?
https://stackoverflow.com/questions/39650122/how-to-ensure-constexpr-function-never-called-at-runtime

from constexpr.

LB-- avatar LB-- commented on August 11, 2024

There is consteval in the C++20 standard now: https://en.cppreference.com/w/cpp/language/consteval

from constexpr.

Related Issues (9)

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.