Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Errors after updating to GCC 12

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++?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

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 preffered 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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading