Are you talking about gcc -Wignored-qualifiers? It seems like such warning is only emitted where the function is *defined*, not where the function is *called*. Example: --- const int f(void) { return 1; } int main() { return f(); } --- Output: --- $ gcc -Wextra y.c -o y y.c:1:1: warning: type qualifiers ignored on function return type [-Wignored-qualifiers] 1 | const int f(void) { return 1; } | ^~~~~ --- I'm only able to get a compile *error* when a macro is used as a l-value. Example: --- struct Point { int x; int y; }; #define POINT_X(p) ((int)p.x) int main() { struct Point p = {1, 2}; int x = POINT_X(p); // r-value ok POINT_X(p) = 1; // l-value ERROR return 0; } --- With "#define POINT_X(p) (p.x)", the macro can be used as l-value and r-value. Victor On Wed, Dec 8, 2021 at 1:43 AM Greg Ewing <greg.ewing@canterbury.ac.nz> wrote:
On 8/12/21 4:36 am, Antoine Pitrou wrote:
Is there a way to emit a compilation warning when those macros are used as l-values? Even if only enabled on some compilers.
Maybe the macro could be written so that it expands to something with a cast around it? I think gcc has an option for warning about casts used as l-values.
-- Greg _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-leave@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/DG6GBX6O... Code of Conduct: http://python.org/psf/codeofconduct/
-- Night gathers, and now my watch begins. It shall not end until my death.