public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/94379] New: Feature request: like clang, support __attribute((__warn_unused_result__)) on structs, unions, and enums
@ 2020-03-28 11:01 pskocik at gmail dot com
2020-03-28 22:27 ` [Bug c/94379] " msebor at gcc dot gnu.org
2023-04-23 7:44 ` pskocik at gmail dot com
0 siblings, 2 replies; 3+ messages in thread
From: pskocik at gmail dot com @ 2020-03-28 11:01 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94379
Bug ID: 94379
Summary: Feature request: like clang, support
__attribute((__warn_unused_result__)) on structs,
unions, and enums
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c
Assignee: unassigned at gcc dot gnu.org
Reporter: pskocik at gmail dot com
Target Milestone: ---
Clang supports applying the warn_unused_result attribute to enums, structs, and
unions, which has the effect that functions returning such an attributed
enum/struct/union behaves as if it itself had the warn_unused_result attribute.
Example:
typedef struct __attribute__((__warn_unused_result__)) aStructType{ int x; }
aStructType;
aStructType getStruct(void);
typedef union __attribute__((__warn_unused_result__)) aUnionType{ int x; }
aUnionType;
aUnionType getUnion(void);
typedef enum __attribute__((__warn_unused_result__)) anEnumType{
anEnumarationConstant } anEnumType;
anEnumType getEnum(void);
int main()
{
getEnum();
getStruct();
getUnion();
}
// https://gcc.godbolt.org/z/jyHhLx
I find this to be a very useful feature, and it would be nice if gcc had it
(along with its current un-void-able warn_unused_result
(https://gcc.gnu.org/bugzilla/show_bug.cgi?id=66425)).
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/94379] Feature request: like clang, support __attribute((__warn_unused_result__)) on structs, unions, and enums
2020-03-28 11:01 [Bug c/94379] New: Feature request: like clang, support __attribute((__warn_unused_result__)) on structs, unions, and enums pskocik at gmail dot com
@ 2020-03-28 22:27 ` msebor at gcc dot gnu.org
2023-04-23 7:44 ` pskocik at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: msebor at gcc dot gnu.org @ 2020-03-28 22:27 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94379
Martin Sebor <msebor at gcc dot gnu.org> changed:
What |Removed |Added
----------------------------------------------------------------------------
Last reconfirmed| |2020-03-28
CC| |msebor at gcc dot gnu.org
Ever confirmed|0 |1
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
--- Comment #1 from Martin Sebor <msebor at gcc dot gnu.org> ---
Confirmed.
C2X will likely have the same [[nodiscard]] attribute as C++. GCC 10
recognizes [[nodiscard]] but ignores it with a warning. In both languages the
attribute can be applied to enums, structures, and unions as well. The latest
proposal is http://www.open-std.org/jtc1/sc22/wg14/www/docs/n2267.pdf. But I
think it makes sense to extend warn_unused_result so that it can be used in
earlier language conformance modes, and for compatibility with Clang.
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/94379] Feature request: like clang, support __attribute((__warn_unused_result__)) on structs, unions, and enums
2020-03-28 11:01 [Bug c/94379] New: Feature request: like clang, support __attribute((__warn_unused_result__)) on structs, unions, and enums pskocik at gmail dot com
2020-03-28 22:27 ` [Bug c/94379] " msebor at gcc dot gnu.org
@ 2023-04-23 7:44 ` pskocik at gmail dot com
1 sibling, 0 replies; 3+ messages in thread
From: pskocik at gmail dot com @ 2023-04-23 7:44 UTC (permalink / raw)
To: gcc-bugs
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94379
--- Comment #2 from Petr Skocik <pskocik at gmail dot com> ---
Excellent!
For optional super extra coolness, this might work (and clang doesn't do this)
with statement expressions too so that statement expression-based macros could
be
marked warn_unused_result through it too.
typedef struct __attribute((__warn_unused_result__)) { int x; }
wur_retval_t;
wur_retval_t foo(void){ int x=41; return (wur_retval_t){x+1}; }
#define foo_macro() ({ int x=41; (wur_retval_t){x+1}; })
void use(void){
foo(); //warn unused result ✓
foo_macro(); //perhaps should "warn unused result" too?
}
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2023-04-23 7:44 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-28 11:01 [Bug c/94379] New: Feature request: like clang, support __attribute((__warn_unused_result__)) on structs, unions, and enums pskocik at gmail dot com
2020-03-28 22:27 ` [Bug c/94379] " msebor at gcc dot gnu.org
2023-04-23 7:44 ` pskocik at gmail dot com
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).