https://gcc.gnu.org/bugzilla/show_bug.cgi?id=102092
Bug ID: 102092 Summary: [C++2b] Passing argument to auto template parameter modifies the value of argument inside function Product: gcc Version: 12.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: andrei.popa105 at yahoo dot com Target Milestone: --- Created attachment 51364 --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=51364&action=edit In this cpp file, I have created a structure that models a polynomial function. Outside of this structure I have created 2 template functions for adding and multiplying 2 polynomials. Hi, For this example, I used gcc trunk (gcc version 12.0.0 experimental) on x86-64 platform. For compiling, I used the following command: - g++ auto_template_paramater_bug.cpp -O3 -std=c++2b -Wall -Wextra -Wpedantic -o bug_report In auto_template_paramater_bug.cpp file, I have created a structure that models a polynomial function. Outside of this structure I have created 2 templated functions using auto template parameter for adding and multiplying 2 polynomials, called add and mult. In main function I multiplied polynomials p1 and p2, polynomials p3 and p4, and after that I multiplied these 2 results. All works fine until I made an addition of polynomials p1 and p5. As you can see from these example, if I pass p5 to function add through auto template parameter, the value of p5 is different in function add that it is in main function (look at p5 and p5_passed_to_add_function in the output of the program). I have 2 mentions: 1) If you comment out all those multiplies for making only the addition, the values are passed correctly through function add. 2) As you can see, the type for values of coefficients for those polynomial functions are double through Type macro. If you change Type to be another type like an integral or float or long double, the code works as expected. It seems that it is a problem with double type. For another information, I am here to answer. Thank you, Andrei