Giter VIP home page Giter VIP logo

Comments (2)

andreasfertig avatar andreasfertig commented on September 26, 2024

Hello @Ukilele,

that looks like an interesting question. From the paragraphs you quote, I agree your interpretation seems correct.

If we look at the AST from Clang (compiler-explorer.com/z/K3f5jzscE) we can see that B's operator is not constexpr. The behavior of C++ Insights matches what Clang thinks.

Now, there is one piece missing, which I couldn't find quickly. It does not make sense to mark the assignment operators constexpr in B since we can never use them in a constexpr context. For example, the compilation fails if you uncomment line 13 in the Compiler Explorer link.

I can see that eel.is/c++draft/dcl.constexpr#3 does not say that, which is confusing. I'll ask WG21 whether there is some text missing or there is a sub-clause somewhere addressing this behavior.

Andreas

from cppinsights.

Ukilele avatar Ukilele commented on September 26, 2024

Hi Andreas,
thanks a lot for your comprehensive response.

I agree that B is a contrived example. Having a class with a constexpr assignment operator but with a non-constexpr destructor is at most useful for theoretical discussions. I just was playing around on cppinsights, because it was not completely clear to me when a defaulted special member function is constexpr or noexcept and your tool is very helpful to find that out!

The reason that line 13 fails to compile is, because the destructor of B is user-provided (showstopper for C++17) and not marked as constexpr (showstopper for C++20). But you are right, I think we can never actually use them in a constexpr context, because we can't use B in a constexpr context, as it's destructor is not constexpr.

So far I still think that the assignment operators of B, D and D<false> should be marked constexpr. But I see that the issue would be on Clang and not on cppinsights.

from cppinsights.

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.