numeric_limits<array type> generates a compiler error

Daniel Krügler daniel.kruegler@gmail.com
Wed Feb 6 18:36:00 GMT 2013


2013/2/6 Daniel Krügler <daniel.kruegler@gmail.com>:
> 2013/2/6 Andy Venikov <avenikov@google.com>:
>> I thought that numeric_limits were supposed to work for any type, not
>> just arithmetic types.
>
> I think it does depend on what you mean with "supposed to work".
>
>> The following program, when compiled with gcc 4.7.2, gives a compiler error.
>>
>> #include <limits>
>>
>> int main(int, char**)
>> {
>>    bool b = std::numeric_limits<char[10]>::is_integer;
>> }
>>
>> /limits:309:7: error: function returning an array
>>
>> The function in question is min()
>>
>> Is this a problem? Or is it expected?
>
> Good question, but I would expect that your code would instantiate the
> primary template of numeric_limits. Doing so and attempting to access
> is_integer seems like a valid request to me as indicated layout of the
> primary template synopsis. There is also evidence for this by explicit
> wording in p1:
>
> "The default numeric_limits<T> template shall have all members, but
> with 0 or false values."
>
> I would expect that your code should work.

Oops, I need to correct myself. When instantiating the primary
template the function declarations will also be instantiates and this
example would indeed result in an invalid attempt to declare

static constexpr char[10] min() noexcept;

and all other functions. So, this is supposed to be ill-formed.

- Daniel



More information about the Libstdc++ mailing list