Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Well, my money is on a bug. You don't mention which compiler you're using, but the stdafx suggests a variety of Visual Studio, which I don't have.</p> <p>The specification says that decltype(e) should have the type of e if e is an entity. An entity is a value, object, reference, function, enumerator, type, class member, template, template specialization, namespace, parameter pack, or this. In your example, Mantissa is a prvalue by virtue of being a non-class template parameter, which, as near as I can tell is a value and therefore an entity. So, it appears that it should work, according to the spec.</p> <p>I've tried your code (with minor, irrelevant modifications) in two other compilers: CodeGear RAD Studio 2010 and g++ 4.3.4. In RAD Studio, it fails to find the correct template: I get 'cannot find "max"'. If I add a "max" enum value to the base NumericLimits class, the static_assert finds that value and does a comparison.</p> <p>In g++, I get internal compiler errors.</p> <p>For what it's worth, you can 'launder' the type through a static variable like so:</p> <pre><code> template&lt;short Mantissa, short Exponent, short Base = 10&gt; class AllocFactorScientific { static decltype(Mantissa) MantissaLaundry; static_assert(Mantissa &gt; 0,"Mantissa component MUST be &gt; zero"); //why if this works: static_assert(Mantissa &lt; NumericLimits&lt;short&gt;::max, "Provided number is too large."); //this works as well now: static_assert(Mantissa &lt; NumericLimits&lt;decltype(MantissaLaundry)&gt;::max, "Provided number is too large."); private: long double factor_; </code></pre> <p>This appears to work in RAD Studio, perhaps it will as well in Visual Studio. Alternately, you can narrow down the issue and file a bug report.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload