[aspectc-user] Problem with static member variable in template class

Matthias Urban matthias.urban at pure-systems.com
Tue Jun 8 23:54:09 CEST 2010


Hi,

thanks for the bug report. The problem is located in the look-ahead for
assignment expressions. It doesn't deal correctly with template-ids. To
be fixed within the next days.

Regards,
Matthias


> i have an problem with the following piece of code:
> 
> ================================================================================
> #include <stdlib.h>
> #include <stdint.h>
> 
> template<typename _OPMODE_T, uint16_t _GROUP> class Test {
>     private:
>         static _OPMODE_T opMode;
> 
>     public:
>         void setOpMode(_OPMODE_T newMode);
> };
> 
> template<typename _OPMODE_T, uint16_t _GROUP> void Test<_OPMODE_T, _GROUP>::setOpMode(_OPMODE_T newMode) {
> // Error: error: invalid statement near token `='
>     Test<_OPMODE_T, _GROUP>::opMode = newMode;
> 
> // Works
> //  opMode = newMode;
> }
> 
> template<typename _OPMODE_T, uint16_t _GROUP> _OPMODE_T Test<_OPMODE_T, _GROUP>::opMode = _OPMODE_T();
> 
> ================================================================================
> 
> 
> Compiling the code with: ag++ --real-instances results in the following error message:
> error: invalid statement near token `='
> 
> As you see in the code, if i remove the type in front of opMode then ag++ stops complaining.
> g++ has no problem with both variants.
> 
> 
> I just wanted to reduce the code and removed the second template parameter and
> figured out that the following pieces of code also compile without errors:
> 
> ================================================================================
> #include <stdlib.h>
> #include <stdint.h>
> 
> template<typename _OPMODE_T> class Test {
>     private:  
>         static _OPMODE_T opMode;
> 
>     public:
>         void setOpMode(_OPMODE_T newMode);
> };
> 
> template<typename _OPMODE_T> void Test<_OPMODE_T>::setOpMode(_OPMODE_T newMode) {
>     Test<_OPMODE_T>::opMode = newMode;
> }
> 
> template<typename _OPMODE_T> _OPMODE_T Test<_OPMODE_T>::opMode = _OPMODE_T();
> 
> ================================================================================
> #include <stdlib.h>
> #include <stdint.h>
> 
> template<uint16_t _GROUP> class Test {
>     private:
>         static uint16_t opMode;
> 
>     public:
>         void setOpMode(uint16_t newMode);
> };
> 
> template<uint16_t _GROUP> void Test<_GROUP>::setOpMode(uint16_t newMode) {
>     Test<_GROUP>::opMode = newMode;
> }
> 
> template<uint16_t _GROUP> uint16_t Test<_GROUP>::opMode;
> 
> ================================================================================
> 
> 
> Regards,
> Jens




More information about the aspectc-user mailing list