public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/67358] New: const makes the code behavior changes
@ 2015-08-26 9:09 liweifriends at gmail dot com
2015-08-26 9:19 ` [Bug c++/67358] " redi at gcc dot gnu.org
0 siblings, 1 reply; 2+ messages in thread
From: liweifriends at gmail dot com @ 2015-08-26 9:09 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67358
Bug ID: 67358
Summary: const makes the code behavior changes
Product: gcc
Version: 5.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: liweifriends at gmail dot com
Target Milestone: ---
#include <iostream>
#include <map>
#include <string>
using namespace std;
struct LoadModel;
template<typename T>
class Hello
{
public:
template<typename TLayerOp, typename...TArgs>
friend void LayerOperation(TLayerOp*,
Hello& p_layer,
TArgs&&...args)
{
cout << 10 << endl;
}
friend void LayerOperation(LoadModel*,
Hello& p_layer,
int& p)
{
cout << 20 << endl;
}
};
int main()
{
int p;
Hello<bool> h;
LayerOperation(static_cast<LoadModel*>(nullptr), h, p);
}
Currently, the code output 20, means the second LayerOperation function is
invoked.
But if I modify its third parameter as follows:
friend void LayerOperation(LoadModel*,
Hello& p_layer,
const int& p)
{
cout << 20 << endl;
}
The code will output 10, means the first LayerOperation function is invoked.
Is this a feature or a bug?
^ permalink raw reply [flat|nested] 2+ messages in thread
* [Bug c++/67358] const makes the code behavior changes
2015-08-26 9:09 [Bug c++/67358] New: const makes the code behavior changes liweifriends at gmail dot com
@ 2015-08-26 9:19 ` redi at gcc dot gnu.org
0 siblings, 0 replies; 2+ messages in thread
From: redi at gcc dot gnu.org @ 2015-08-26 9:19 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=67358
Jonathan Wakely <redi at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution|--- |INVALID
--- Comment #1 from Jonathan Wakely <redi at gcc dot gnu.org> ---
Not a bug, that's how C++ works.
The argument p is a non-const int, so binding const int& requires a
qualification conversion. The function template deduces the parameter type as
int& which is an exact match requiring no conversion, so is a better conversion
sequence.
I suggest asking this kind of question somewhere like stackoverflow.com instead
of reporting a bug.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2015-08-26 9:19 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2015-08-26 9:09 [Bug c++/67358] New: const makes the code behavior changes liweifriends at gmail dot com
2015-08-26 9:19 ` [Bug c++/67358] " redi 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).