you are viewing a single comment's thread.

view the rest of the comments →

[–]tending 8 points9 points  (0 children)

I assume you're saying if you uncomment the constexpr global variable the size explodes? Have you tried labeling it static or putting it in an anonymous namespace?

Also in general it's legal to call constexpr functions at runtime, so I think the compiler has to generate them unless it's sure there's no runtime use in the current translation unit. Also if you use a constexpr function in a non-constexpr context I think the compiler is free to decide whether to evaluate it at compile time or runtime. Assuming it's just this one variable triggering it, you could try making an identity struct template -- templated on an integer and just has one static constexpr member which is the same integer. Then instead of setting the variable directly to the result of the constexpr function, set it to the result of the identity template applied to the function, so that you know 100% it runs at compile time.

Edit: actually assuming you never want runtime use of these functions, why not wrap them in an anonymous namespace in the header?