Skip to content

Fix unused variable warning in GCC 16+ - #198

Closed
ilazaric wants to merge 2 commits into
edgcpp:mainfrom
ilazaric:ilazaric/warn-unused
Closed

ilazaric wants to merge 2 commits into
edgcpp:mainfrom
ilazaric:ilazaric/warn-unused

Conversation

@ilazaric

@ilazaric ilazaric commented Oct 2, 2026 •

Copy link
Copy Markdown
Contributor

Locally I built this with trunk GCC and noticed warnings:

In file included from /home/ilazaric/repos/ALL/submodules/edg-compiler/src/fe_common.h:71,
                 from /home/ilazaric/repos/ALL/submodules/edg-compiler/src/c_gen_be.c:45:
/home/ilazaric/repos/ALL/submodules/edg-compiler/src/util.h: In instantiation of 'void edg::detail::append_with_custom_reserve(a_Reserve_fn, a_Text_convertible_type ...) [with a_Reserve_fn = edg::Allocated_string<edg::Delegate_buffered_allocator<50, edg::General_allocator>::Meta>::Allocated_string<>(const an_allocator&)::<lambda(size_t)>; a_Text_convertible_type = {}]':
/home/ilazaric/repos/ALL/submodules/edg-compiler/src/util.h:4957:37:   required from 'edg::Allocated_string<Allocator>::Allocated_string(const an_allocator&, a_Text_convertible_type ...) [with a_Text_convertible_type = {}; Allocator = edg::Delegate_buffered_allocator<50, edg::General_allocator>::Meta; an_allocator = edg::Delegate_buffered_allocator<50, edg::General_allocator>::Meta<char>]'
 4957 |   detail::append_with_custom_reserve(reserve_func, args...);
      |   ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~
/home/ilazaric/repos/ALL/submodules/edg-compiler/src/util.h:4905:47:   required from 'edg::Allocated_string<Allocator>::Allocated_string(a_Text_convertible_type ...) [with a_Text_convertible_type = {}; Allocator = edg::Delegate_buffered_allocator<50, edg::General_allocator>::Meta]'
 4905 |     : Allocated_string(an_allocator{}, args...)
      |                                               ^
/home/ilazaric/repos/ALL/submodules/edg-compiler/src/c_gen_be.c:4141:22:   required from here
 4141 |     Small_string<50> buffer;
      |                      ^~~~~~
/home/ilazaric/repos/ALL/submodules/edg-compiler/src/util.h:4861:10: warning: variable 'counter' set but not used [-Wunused-but-set-variable=]
 4861 |   size_t counter = 0;
      |          ^~~~~~~

Tried a couple of different GCC versions, and first one that warns is GCC 16.

Minimum warning to see this: -Wunused-but-set-variable=2 , which is implied by the build

It seems GCC warns now if a variable is only used in a pack expansion over an empty pack.
I believe this is equivalent to: https://godbolt.org/z/o4535qKqc

Don't think it has much interesting info, but just noting how I configured and built:

# GCC trunk installed to /opt/GCC-release, and bin is in PATH
export EDG_BASE="$PWD/bases/docker/dev-env/gcc"
time LDFLAGS='-Wl,-rpath=/opt/GCC-release/lib64' cmake --preset linux-gcc-release -DEDG_CPP_RT_LIBS=linux_x86_64
time LDFLAGS='-Wl,-rpath=/opt/GCC-release/lib64' cmake --build build/gcc-release/ --target src/cmake/cpfe/CMakeFiles/cpfe.dir/__/__/c_gen_be.c.o --clean-first --verbose

If needed, I can cook up a podman reproducer

Not very relevant, but interesting to me, the warning disappears if operator[] is not on class, but pointer:
https://godbolt.org/z/1G1aWcKan

After this fix, haven't seen any warning over full build

@daveedvdv-nvidia

Copy link
Copy Markdown

Looks good in principle. Just the formatting nit I pointed out.
I think this doesn't need a Changes entry.

@ilazaric

ilazaric commented Oct 2, 2026

Copy link
Copy Markdown
Contributor Author

@daveedvdv-nvidia I think your nit message got lost, I assume you meant I should align the variable identifiers? If so, I believe I updated it to look as rest of codebase.

@daveedvdv-nvidia

Copy link
Copy Markdown

I think your nit message got lost,

Ah, I probably forgot to click something...

I assume you meant I should align the variable identifiers?

Exactly. Your change looks good!

@daveedvdv-nvidia

Copy link
Copy Markdown

Merged as b8d3a78

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants