Bug 22344
Summary: | strcmp of different strings returns 0 | ||
---|---|---|---|
Product: | [Retired] Red Hat Linux | Reporter: | Todd Stout <tstout> |
Component: | gcc | Assignee: | Jakub Jelinek <jakub> |
Status: | CLOSED NOTABUG | QA Contact: | David Lawrence <dkl> |
Severity: | medium | Docs Contact: | |
Priority: | medium | ||
Version: | 7.0 | ||
Target Milestone: | --- | ||
Target Release: | --- | ||
Hardware: | i686 | ||
OS: | Linux | ||
Whiteboard: | |||
Fixed In Version: | Doc Type: | Bug Fix | |
Doc Text: | Story Points: | --- | |
Clone Of: | Environment: | ||
Last Closed: | 2000-12-15 13:57:45 UTC | Type: | --- |
Regression: | --- | Mount Type: | --- |
Documentation: | --- | CRM: | |
Verified Versions: | Category: | --- | |
oVirt Team: | --- | RHEL 7.3 requirements from Atomic Host: | |
Cloudforms Team: | --- | Target Upstream Version: | |
Embargoed: |
Description
Todd Stout
2000-12-15 13:57:42 UTC
No, if you have const & there then the program is buggy. You even get a nice warning about it: o.C: In method `const char *const &StrContainer::getStr ()': o.C:15: warning: returning reference to temporary Here is what's going on: as strVal is char * and you're returning const reference to const char *, it cannot be reference to strVal (because it is char *), so it has to be copied into temporary variable from which you then take reference. But then it really depends with what stack pointer are both getStr routines called (not speaking that the stack slot may be clobbered by interrupt handlers and stuff like that at that point). So, you can e.g.: - change the type of strVal to const char * (likewise with the constructor) - remove that const & - change return type of getStr to char * const & compile with optimizations (then it gets inlined and can work (but by pure luck). g++ -O2 on this gives twice Not Equal. As for __pure__, it is a weaker cousin of __const__, meaning that the function does not clobber any memory (well, it is allowed to clobber stack below stack pointer obviously). This is so that e.g. compiler does not have to reload its own copies of global variables which could be potentially clobbered by call to non-"pure" function. |