public inbox for gcc@gcc.gnu.org
 help / color / mirror / Atom feed
* Apparent deeply-nested missing error bug with gcc 7.3
@ 2018-06-18  8:46 Soul Studios
  2018-06-18 11:21 ` Jonathan Wakely
  0 siblings, 1 reply; 8+ messages in thread
From: Soul Studios @ 2018-06-18  8:46 UTC (permalink / raw)
  To: gcc

In the following case GCC correctly throws an error since 
simple_return_value is returning a pointer, not a reference:

"#include <iostream>

int & simple_return_value(int &temp)
{
	return &temp;
}


int main()
{
	int temp = 42;
	return simple_return_value(temp);
}"



However in deeply-nested code GCC appears to miss the error, and in fact 
still returns a reference despite the return value of a pointer.

Take the following code in plf_list 
(https://github.com/mattreecebentley/plf_list):

"template<typename... arguments>
inline PLF_LIST_FORCE_INLINE reference emplace_back(arguments &&... 
parameters)
{
	return (emplace(end_iterator, 
std::forward<arguments>(parameters)...)).node_pointer->element;
}
"


emplace returns an iterator which contains a pointer to a node, which is 
then used to return the element at that node. However if you change the 
line to:
	"return &((emplace(end_iterator, 
std::forward<arguments>(parameters)...)).node_pointer->element);"


GCC 7.3 doesn't blink. Worse, it appears to return a reference anyway. 
The test suite cpp explicitly tests the return value of emplace_back, so 
changing the line should result in a test fail as well as a compile 
error. Neither occur.
You can test this yourself by downloading the code + test suite at 
http://www.plflib.org/plf_list_18-06-2018.zip
and editing the line yourself (line 1981).

Clang 3.7.1 detects the error immediately.


I'm not sure at which stage this bug appears. Templating the code at the 
top of this mail doesn't recreate the bug, so it must be something to do 
with templated classes (I'm guessing here).

Hopefully someone can shed some light on this.

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

end of thread, other threads:[~2018-06-21  7:39 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-06-18  8:46 Apparent deeply-nested missing error bug with gcc 7.3 Soul Studios
2018-06-18 11:21 ` Jonathan Wakely
2018-06-18 12:35   ` Jonathan Wakely
2018-06-19  0:31     ` Soul Studios
2018-06-19 10:04     ` Soul Studios
2018-06-19 10:37       ` Jonathan Wakely
2018-06-19 18:30         ` Jason Merrill
2018-06-21  8:21         ` Soul Studios

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).