Reputation: 342
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?
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.
Upvotes: 6
Views: 3216
Reputation: 433
Ignore intellisense if it compiles. It sometimes just spits out wrong warnings.
Upvotes: 6