Bug 96096 - g++-10.1 silently ignores function violating const instead of refusing to compile
Summary: g++-10.1 silently ignores function violating const instead of refusing to com...
Status: RESOLVED DUPLICATE of bug 95789
Alias: None
Product: gcc
Classification: Unclassified
Component: c++ (show other bugs)
Version: 10.1.0
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2020-07-07 15:59 UTC by Nicolas Sillitoe
Modified: 2020-07-07 16:10 UTC (History)
1 user (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments
Minimal bug reproduction code (161 bytes, text/plain)
2020-07-07 15:59 UTC, Nicolas Sillitoe
Details

Note You need to log in before you can comment on or make changes to this bug.
Description Nicolas Sillitoe 2020-07-07 15:59:48 UTC
Created attachment 48842 [details]
Minimal bug reproduction code

Attached code compiled with:

g++-10 (Ubuntu 10.1.0-2ubuntu1~18.04) 10.1.0

with compile line:
g++-10 Const_Violation_Silent_Error.cpp -o Const_Violation_Silent_Error

compiles whereas g++-9 (g++-9 (Ubuntu 9.3.0-11ubuntu0~18.04.1) 9.3.0) correctly refuses to with error:

error: binding reference of type ‘dummy&’ to ‘const dummy’ discards qualifiers...

Not only does this code compile when it should not, but it will simply quietly never enter Modify_Object().

Copy of attached code:

struct dummy{
	int int_param;
};

inline void Modify_Object(dummy &object){
	object.int_param=0;
}

template <bool is_learning=true> void Templated_Function(){
	const dummy R{0};
	Modify_Object(R);
}

int main(){
	Templated_Function();
}
Comment 1 Marek Polacek 2020-07-07 16:10:41 UTC
Thanks for the report.  Dup.

*** This bug has been marked as a duplicate of bug 95789 ***