Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set an attribute for all C++ functions without changing code?

Tags:

c++

gcc

I'd like to use the -Wunused-result option in GCC to detect unused/ignored return values in my code. But this requires marking the function declarations either with an attribute, or with attribute specifier sequence.

Doing this by hand could be very time consuming and error-prone. I was wondering if there is a way to tell GCC to set attributes for all functions (or set a default attribute), so that I could use the warning flag.

like image 743
Machta Avatar asked Nov 03 '17 18:11

Machta


1 Answers

This looks like a job for a GCC plugin. Upstream might also accept a patch which sets the attribute for all subsequent functions using a pragma, but the exact semantics are probably quite tricky for C++.

like image 99
Florian Weimer Avatar answered Oct 02 '22 12:10

Florian Weimer