Nice find! The commit message states “However, it requires exactly specifying the array size, which can be
cumbersome,” but I don’t think this is true.
Using the test program:
0// repro.c
1#include <stdio.h>
2
3int main() {
4 char str[] = "hello world"; // This should trigger the warning
5 printf("%s\n", str);
6 return 0;
7}
I am able to compile with gcc14:
0nix-shell --expr 'with import <nixpkgs> {}; mkShell.override { stdenv = overrideCC stdenv gcc14; }'
1gcc -v
2gcc -Wall -Wextra -Wpedantic -Werror repro.c -o out
and able to compile with gcc15:
0nix-shell --expr 'with import <nixpkgs> {}; mkShell.override { stdenv = overrideCC stdenv gcc15; }'
1gcc -v
2gcc -Wall -Wextra -Wpedantic -Werror repro.c -o out
However, if I specify the array size, I can reproduce the error:
0// repro.c
1#include <stdio.h>
2
3int main() {
4 char str[11] = "hello world"; // This should trigger the warning
5 printf("%s\n", str);
6 return 0;
7}
No error with:
0nix-shell --expr 'with import <nixpkgs> {}; mkShell.override { stdenv = overrideCC stdenv gcc14; }'
1gcc -Wall -Wextra -Wpedantic -Werror repro.c -o out
And an error with:
0nix-shell --expr 'with import <nixpkgs> {}; mkShell.override { stdenv = overrideCC stdenv gcc15; }'
1gcc -Wall -Wextra -Wpedantic -Werror repro.c -o out
2
3repro.c: In function ‘main’:
4repro.c:4:20: error: initializer-string for array of ‘char’ truncates NUL terminator but destination lacks ‘nonstring’ attribute (12 chars into 11 available) [-Werror=unterminated-string-initialization]
5 4 | char str[11] = "hello world"; // This should trigger the warning
6 | ^~~~~~~~~~~~~
7cc1: all warnings being treated as errors
Based on the above, I’d recommend we prefer the approach in this PR of not specifying the array size and perhaps document it as the preferred convention going forward? I find being able to specify the tag as a string to be much more reviewable than specifying the tag as an array of characters.
That being said, also happy to go the other way and update the musig tests to match the other modules if thats the preferred convention, as I think the main benefit is to have all of the modules follow the same convention.