Values as template parameters (compiler bug?) 
Author Message
 Values as template parameters (compiler bug?)

Hi,

is the following a compiler bug (VC.Net)?

---

#include <cassert>

template <typename T, T MinValue, T MaxValue>
class Range
{
public:
    static bool Accepts(const T& value)
    {
        return (( value >= MinValue) && (value <= MaxValue));
    }

Quote:
};

int main(int, char*[])
{
    assert((Range<double, 0.0, 90.0>::Accepts(90.0)));
    assert((Range<double, 0.0, 180.0>::Accepts(180.0)));    // FAILS:
Range<double, 0.0, 180.0> not instantiated, using Range<double, 0.0, 90.0>

Quote:
}

---

It seems like the compiler isn't actually instantiating the second variant.
I guess I could work around it by also passing some kind of dummy struct
(e.g. "struct foo_0to180 {};" ) as a fourth parameter, but that would soon
get really, really tedious.

Comments, anyone?

// Johan



Mon, 08 Nov 2004 17:05:26 GMT  
 Values as template parameters (compiler bug?)

Quote:

> Hi,

> is the following a compiler bug (VC.NET)?

> ---

> #include <cassert>

> template <typename T, T MinValue, T MaxValue>
> class Range
> {
> public:
>     static bool Accepts(const T& value)
>     {
>         return (( value >= MinValue) && (value <= MaxValue));
>     }
> };

> int main(int, char*[])
> {
>     assert((Range<double, 0.0, 90.0>::Accepts(90.0)));
>     assert((Range<double, 0.0, 180.0>::Accepts(180.0)));    // FAILS:
> Range<double, 0.0, 180.0> not instantiated, using Range<double, 0.0, 90.0>
> }

> ---

> It seems like the compiler isn't actually instantiating the second variant.
> I guess I could work around it by also passing some kind of dummy struct
> (e.g. "struct foo_0to180 {};" ) as a fourth parameter, but that would soon
> get really, really tedious.

> Comments, anyone?

> // Johan

It's strange that this compiles at all (which might be a bug of it's own);
AFAIK floating point values are illegal as template arguments.

Radoslav Getov



Wed, 10 Nov 2004 00:07:26 GMT  
 Values as template parameters (compiler bug?)


[snip]

Quote:

> It's strange that this compiles at all (which might be a bug of it's own);
> AFAIK floating point values are illegal as template arguments.

> Radoslav Getov


Floating point non-type template parameters are currently supported as an
extension.  ISO C++ specifically disallows them.

We plan on removing support for this extension in the upcoming release.
Issues like this were a big motivation for this decision.

Jason Shirk
VC++ Compiler Team



Wed, 10 Nov 2004 01:31:21 GMT  
 Values as template parameters (compiler bug?)
Thanks for the reply. Yes, it would be a good idea to remove the support or
at least make it disabled by default.

// Johan



Quote:




> [snip]

> > It's strange that this compiles at all (which might be a bug of it's
own);
> > AFAIK floating point values are illegal as template arguments.

> > Radoslav Getov

> Floating point non-type template parameters are currently supported as an
> extension.  ISO C++ specifically disallows them.

> We plan on removing support for this extension in the upcoming release.
> Issues like this were a big motivation for this decision.

> Jason Shirk
> VC++ Compiler Team



Fri, 12 Nov 2004 04:02:23 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. template template parameter with default value (VS.NET 2003)

2. VC 7.1 final beta: bug with template template parameters

3. Possible bug with template template parameters in VC++ 7.0

4. Bug in inheritance from template template parameters in VC7

5. C++ compiler bug: template and non template function overload resolution

6. VC7 does NOT support template-template parameters involving non-type parameters

7. WORKAROUND: nested template type default parameter values

8. BUG: pointer to __fastcall function as template parameter

9. unreported bug with default template parameter

10. template parameter type internal compiler error

11. MS compiler seems to mal function/setting const value to template function

12. Compiler Bug with template constructors?

 

 
Powered by phpBB® Forum Software