silentbicycle / greatest

A C testing library in 1 file. No dependencies, no dynamic allocation. ISC licensed.
ISC License
1.48k stars 108 forks source link

The variable `exp` can shadow `exp(3)` when including `math.h`. #80

Closed sw17ch closed 5 years ago

sw17ch commented 6 years ago

When building a test suite using greatest.h, it's possible to get a shadowing warning about exp's use. This is the name of a function available in math.h as well.

I've been unable to produce this on GCC versions other than 4.6.3.

Greatest Version: 1.4.0

GCC output:

$ gcc -Wshadow greatest_exp_repro.c -o ger
greatest_exp_repro.c: In function 'greatest_do_assert_equal_t':
greatest_exp_repro.c:14:1: warning: declaration of 'exp' shadows a global declaration [-Wshadow]
greatest_exp_repro.c: In function 'greatest_string_equal_cb':
greatest_exp_repro.c:14:1: warning: declaration of 'exp' shadows a global declaration [-Wshadow]
greatest_exp_repro.c: In function 'greatest_memory_equal_cb':
greatest_exp_repro.c:14:1: warning: declaration of 'exp' shadows a global declaration [-Wshadow]

Example File:

/* greatest_exp_repro.c */

#include "math.h"
#include "greatest.h"

TEST test_exp_repro()
{
    PASS();
}

SUITE(test_exp_suite)
{
    RUN_TEST(test_exp_repro);
}

GREATEST_MAIN_DEFS();

int main(int argc, char *argv[])
{
    GREATEST_MAIN_BEGIN();
    RUN_SUITE(test_exp_suite);
    GREATEST_MAIN_END();
}

System Information:

$ uname -a
Linux c02e4fba5a58 4.13.0-39-generic #44~16.04.1-Ubuntu SMP Thu Apr 5 16:43:10 UTC 2018 x86_64 x86_64 x86_64 GNU/Linux

GCC version information:

$ gcc -v
Using built-in specs.
COLLECT_GCC=gcc
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
Target: x86_64-linux-gnu
Configured with: ../src/configure -v --with-pkgversion='Ubuntu/Linaro 4.6.3-1ubuntu5' --with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs --enable-languages=c,c++,fortran,objc,obj-c++ --prefix=/usr --program-suffix=-4.6 --enable-shared --enable-linker-build-id --with-system-zlib --libexecdir=/usr/lib --without-included-gettext --enable-threads=posix --with-gxx-include-dir=/usr/include/c++/4.6 --libdir=/usr/lib --enable-nls --with-sysroot=/ --enable-clocale=gnu --enable-libstdcxx-debug --enable-libstdcxx-time=yes --enable-gnu-unique-object --enable-plugin --enable-objc-gc --disable-werror --with-arch-32=i686 --with-tune=generic --enable-checking=release --build=x86_64-linux-gnu --host=x86_64-linux-gnu --target=x86_64-linux-gnu
Thread model: posix
gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)