Error: expression must have constant value. For a Clearly Constant Value

loaner9

I have a very simple project which is producing odd behavior in VS2015:

#include "Vec2f.h"
#include "StaticRendercomponent.h"

int main(int argc, char** argv)
{
   constexpr Vec2f position(0.0f, 0.0f);
   constexpr PhysicsComponent component(position, 15.0f);

   return 0;
}

VS2015 is highlighting the position argument in the constructor in red. Upon mousing over the highlighting, this message appears:

constexpr Vec2f position = {(0.0f), (0.0f)}

expression must have constant value

Contrary to the error highlighting and the message, the program compiles and runs without a hitch and without any messages in the build log, with warning level 4 and "Treat Warnings As Errors" active.

Having VS show an error like this and proceed to compile my program without even showing the message in the build log is... disconcerting to say the least.

Why is this message being shown?
Why isn't it stopping compilation and running of the application?

The Suspects

Vec2f's Constructor:

constexpr Vec2f::Vec2f(const float x, const float y) noexcept:
   x(x),
   y(y)
{
}

The PhysicsComponent Constructor:

constexpr PhysicsComponent::PhysicsComponent(Vec2f position, float mass, Vec2f momentum) noexcept:
   current(position, mass, momentum),
   previous(current),
   interpolated(current)
{
}

The three data members "current", "previous, "and "interpolated" are of the type PhysicsState, whose constructor is detailed below

constexpr PhysicsState::PhysicsState(Vec2f position, float mass, Vec2f momentum) noexcept:
   mass(mass),
   inverseMass(MathUtils::computeInverse(mass)),
   position(position),
   momentum(momentum),
   externalForce(ZERO_VECTOR)
{
}

The signature of computeInverse is as follows:

template<typename T>
constexpr T computeInverse(T value) noexcept

I still wondered if the PhysicsStates weren't successfully being constexpr initialized by the compiler due to the call to computerInverse(), but adding the line:

constexpr PhysicsState test(position, 15.0f);

To main() compiles and runs with no messages AND no highlighting.
Any insight into this issue would be greatly appreciated.

Tomas Dittmann

Ignore intellisense if it compiles. It sometimes just spits out wrong warnings.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Error[Pe028]: expression must have a constant value

From Dev

2-D Array - Expression must have a constant value error

From Dev

Expression must have a constant value error in an array with the size input by user

From Dev

Array definition - Expression must have a constant value

From Dev

C++ Expression must have constant value

From Dev

c++ expression must have a constant value

From Dev

Intellisense expression must have a constant value

From Dev

Expression must have constant value Eigen matrix

From Dev

"function call must have a constant value in a constant expression"

From Dev

Visual C++ Expression must have a constant value

From Dev

In Java why this error: 'attribute value must be constant'?

From Dev

Compiler showing "Expression must have a constant value" in VS2015 (C Programming)

From Dev

The value for annotation attribute FindBy.xpath must be a constant expression

From Dev

The value for annotation attribute FindBy.xpath must be a constant expression

From Dev

JPA/HIBERNATE: Value must be a constant

From Dev

BuildConfig: Attribute value must be constant

From Dev

Attribute Value must be constant in @Retryable

From Dev

block and expression must have a const value error

From Dev

Index expression must be constant - WebGL/GLSL error

From Dev

Error: "attribute value must be constant". Can I constract a constant from an enum at compile time?

From Dev

Default parameter for value must be a compile time constant?

From Dev

Compiler says an annotation's "value must be a constant"

From Dev

JsonProvider "This is not a constant expression or valid custom attribute value"

From Dev

Value not usable in constant expression alternative pattern

From Dev

Pandas: Get all columns that have constant value

From Dev

Case expressions must be constant expression

From Dev

Case expressions must be constant expression

From Dev

understand a constant expression error

From Dev

"expected constant expression" Error

Related Related

  1. 1

    Error[Pe028]: expression must have a constant value

  2. 2

    2-D Array - Expression must have a constant value error

  3. 3

    Expression must have a constant value error in an array with the size input by user

  4. 4

    Array definition - Expression must have a constant value

  5. 5

    C++ Expression must have constant value

  6. 6

    c++ expression must have a constant value

  7. 7

    Intellisense expression must have a constant value

  8. 8

    Expression must have constant value Eigen matrix

  9. 9

    "function call must have a constant value in a constant expression"

  10. 10

    Visual C++ Expression must have a constant value

  11. 11

    In Java why this error: 'attribute value must be constant'?

  12. 12

    Compiler showing "Expression must have a constant value" in VS2015 (C Programming)

  13. 13

    The value for annotation attribute FindBy.xpath must be a constant expression

  14. 14

    The value for annotation attribute FindBy.xpath must be a constant expression

  15. 15

    JPA/HIBERNATE: Value must be a constant

  16. 16

    BuildConfig: Attribute value must be constant

  17. 17

    Attribute Value must be constant in @Retryable

  18. 18

    block and expression must have a const value error

  19. 19

    Index expression must be constant - WebGL/GLSL error

  20. 20

    Error: "attribute value must be constant". Can I constract a constant from an enum at compile time?

  21. 21

    Default parameter for value must be a compile time constant?

  22. 22

    Compiler says an annotation's "value must be a constant"

  23. 23

    JsonProvider "This is not a constant expression or valid custom attribute value"

  24. 24

    Value not usable in constant expression alternative pattern

  25. 25

    Pandas: Get all columns that have constant value

  26. 26

    Case expressions must be constant expression

  27. 27

    Case expressions must be constant expression

  28. 28

    understand a constant expression error

  29. 29

    "expected constant expression" Error

HotTag

Archive