Is the result of static_casting itself a constexpr pointer constant expression?

clang rejects this code, which gcc allows:

int main() {
    static constexpr const void *vp = nullptr;
    static constexpr const char *cp = static_cast<const char*>(vp);
}

      

With the following:

error: constexpr variable 'cp' must be initialized by a constant expression
  static constexpr const char *cp = static_cast<const char*>(vp);

      

After reading the final list in N3797 5.9 / 2 I don't see anything that prohibits use static_cast

in constant expression, Am I looking in the wrong place or misunderstanding something? Or should I open a bug against clang?

+3


source to share


1 answer


Well, the C ++ 14 standard (and your (not final) draft!) Requires that



a conditional expression e

is a constant constant expression if the evaluation e

, following the rules of the abstract machine (1.9), evaluates one of the following expressions:

- conversion from the cv void *

type to the object pointer type;

+6


source







All Articles