Home > Enterprise >  Errors after updating to GCC 12
Errors after updating to GCC 12

Time:05-28

I have a project where I'm using the datetimepp library and it has been working fine. However I recently did a pacman -Syu and updated gcc. I then compiled the project (which had been compiling properly before that) and compiled it. I got multiple errors complaining "default argument redefinition"

datetimepp/datetime.h:311:96: error: redefinition of default argument for ‘typename std::enable_if<std::is_floating_point<_Tp>::value>::type* <anonymous>’
  311 | template<class Scalar, typename std::enable_if<std::is_floating_point<Scalar>::value>::type* = nullptr>
      |                                                                                                ^~~~~~~
datetimepp/datetime.h:73:96: note: original definition appeared here
   73 | template<class Scalar, typename std::enable_if<std::is_floating_point<Scalar>::value>::type* = nullptr>
      |                                                                                                ^~~~~~~
datetimepp/datetime.h:323:90: error: redefinition of default argument for ‘typename std::enable_if<std::is_integral<_Tp>::value>::type* <anonymous>’
  323 | template<class Scalar, typename std::enable_if<std::is_integral<Scalar>::value>::type* = nullptr>
      |                                                                                          ^~~~~~~
datetimepp/datetime.h:76:90: note: original definition appeared here
   76 | template<class Scalar, typename std::enable_if<std::is_integral<Scalar>::value>::type* = nullptr>
      |                                                                                          ^~~~~~~
datetimepp/datetime.h:335:96: error: redefinition of default argument for ‘typename std::enable_if<std::is_floating_point<_Tp>::value>::type* <anonymous>’
  335 | template<class Scalar, typename std::enable_if<std::is_floating_point<Scalar>::value>::type* = nullptr>
      |                                                                                                ^~~~~~~
datetimepp/datetime.h:79:96: note: original definition appeared here
   79 | template<class Scalar, typename std::enable_if<std::is_floating_point<Scalar>::value>::type* = nullptr>
      |                                                                                                ^~~~~~~
datetimepp/datetime.h:342:90: error: redefinition of default argument for ‘typename std::enable_if<std::is_integral<_Tp>::value>::type* <anonymous>’
  342 | template<class Scalar, typename std::enable_if<std::is_integral<Scalar>::value>::type* = nullptr>
      |                                                                                          ^~~~~~~
datetimepp/datetime.h:82:90: note: original definition appeared here
   82 | template<class Scalar, typename std::enable_if<std::is_integral<Scalar>::value>::type* = nullptr>

Just to confirm that the program was indeed working before I updated, I rolled back the gcc update and the program compiled successfully.

Is this a problem with my program that I should fix, or is it a problem with g ?

CodePudding user response:

Default arguments can only be specified at either declaration or definition but in your case you've specified them at both places.

void foo(int x = 10);
void foo(int x = 10){} // error. redefinition of default arg
void foo(int x){}
foo(); // ok. default arg is 10

So you should remove them from either declaration or definition, definition would be preferred because in between definition and declaration, you wouldn't be able to use those default arguments.

void foo(int x);
foo(); // error. no default arg
void foo(int x = 10){}
foo(); // ok
  • Related