4 Replies Latest reply on Sep 20, 2014 6:17 AM by user522630

    Template declaration error when variable assigned is the same as variable declared


      Hi Fedor,


      In comm-central repository, when compiling mozilla/mfbt/Compression.cpp using -std=c++11, it results in an error as follows:


      "../dist/include/mozilla/CheckedInt.h", line 400: Error: Unexpected type name "T" encountered.

      "../dist/include/mozilla/CheckedInt.h", line 400: Error: value is not defined.

      "../dist/include/mozilla/CheckedInt.h", line 400: Error: No direct declarator preceding ">".

      "../dist/include/mozilla/CheckedInt.h", line 400: Error: A declaration does not specify a tag or an identifier.

      "../dist/include/mozilla/CheckedInt.h", line 400: Error: Default template argument cannot be specified on the definition of a class template member that appears outside of its class.

      "../dist/include/mozilla/CheckedInt.h", line 400: Error: Templates can only declare classes or functions.

      "../dist/include/mozilla/CheckedInt.h", line 413: Error: No primary specialization for partial specialization NegateImpl<T, 0>.

      "../dist/include/mozilla/CheckedInt.h", line 416: Error: Too many arguments for template mozilla::detail::NegateImpl<T>.

      8 Error(s) detected.

      After a check on the file CheckedInt.h, it was narrowed down to the following code that resulted in the failure (the variable assigned, isSigned is the same as variable being declared) :

      template<typename T, bool IsSigned = IsSigned<T>::value>

      struct NegateImpl;


      This code, however compiles without problems in gcc-4.8.


      A workaround was to use a different variable declared in the template (e.g. bool IsTSigned = IsSigned<T>). But I just wanted to be sure whether is this a bug in 12.4 Beta or whether coding rules in templates do allow this kind of declaration? Kindly advise. Thanks.