public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/102092] New: [C++2b] Passing argument to auto template parameter modifies the value of argument inside function
@ 2021-08-27  9:54 andrei.popa105 at yahoo dot com
  2021-08-27 15:40 ` [Bug c++/102092] " andrei.popa105 at yahoo dot com
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: andrei.popa105 at yahoo dot com @ 2021-08-27  9:54 UTC (permalink / raw)
  To: gcc-bugs

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

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2021-09-23 19:01 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-08-27  9:54 [Bug c++/102092] New: [C++2b] Passing argument to auto template parameter modifies the value of argument inside function andrei.popa105 at yahoo dot com
2021-08-27 15:40 ` [Bug c++/102092] " andrei.popa105 at yahoo dot com
2021-08-27 21:23 ` davveston at gmail dot com
2021-08-27 21:33 ` davveston at gmail dot com
2021-09-23 19:01 ` ppalka at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).