ut icon indicating copy to clipboard operation
ut copied to clipboard

Constructor attribute is only working correctly in gcc

Open GomesGoncalo opened this issue 2 years ago • 1 comments

Expected Behavior

❯ ./a.out --help
./a.out [<test name|pattern|tags> ... ] options

with options:
  -? -h --help                  display usage information
  -l --list-tests               list all/matching test cases
  -t, --list-tags               list all/matching tags
  -s, --success                 include successful tests in output
  -o, --out <filename>          output filename
  -r, --reporter <name>         reporter to use (defaults to console)
  -n, --name <name>             suite name
  -a, --abort                   abort at first failure
  -x, --abortx <no. failures>   abort after x failures
  -d, --durations               show test durations
  -D, --min-duration <seconds>  show test durations for [...]
  -f, --input-file <filename>   load test names to run from a file
  --list-test-names-only        list all/matching test cases names only
  --list-reporters              list all reporters
  --order <decl|lex|rand>       test case order (defaults to decl)
  --rng-seed <'time'|number>    set a specific seed for random numbers
  --use-colour <yes|no>         should output be colourised
  --libidentify                 report name and version according to libidentify standard
  --wait-for-keypress <never|start|exit|both>waits for a keypress before exiting

Actual Behavior

❯ ./a.out --help
Suite 'global': all tests passed (5 asserts in 4 tests)

Steps to Reproduce the Problem

  1. Ran this program in my Ubuntu machine https://godbolt.org/z/6a6bW685E
  2. clang++-17 test.cpp -std=c++20
  3. Execute it with command line parameters: ./a.out --help

Works with g++-12 test.cpp -std=c++20

I added some logs into the constructor attribute and the argument parsing function and in clang the attribute is running after the arguments being parsed (hence boost::...::largc is set to 0 when the arguments are parsed) (Possibly a compiler bug? Not sure if this is defined the same way for both compilers)

Specifications

  • Version: whatever got returned from wget https://raw.githubusercontent.com/boost-ext/ut/master/include/boost/ut.hpp today (last commit 6a3d4c1fe3b758b288b9661d9824ccbb8bad26c9)
  • Platform: Linux nix-l-08257 6.2.0-27-generic #28-Ubuntu SMP PREEMPT_DYNAMIC Wed Jul 12 22:39:51 UTC 2023 x86_64 x86_64 x86_64 GNU/Linux
  • Subsystem:

Compiler versions

❯ clang++-17 --version
Ubuntu clang version 17.0.3 (++20231010073144+37b79e779f44-1~exp1~20231010073230.52)

❯ g++-12 --version
g++-12 (Ubuntu 12.3.0-1ubuntu1~23.04) 12.3.0

GomesGoncalo avatar Oct 14 '23 12:10 GomesGoncalo

Is all this hassle really worth it just that we don't have to write

int main(int argc, char** argv) {
    return boost::ut::cfg_main(&argc, &argv);
}

?

This would fix it: #572

jhasse avatar Dec 12 '23 20:12 jhasse

It also seems to run once per translation unit on clang.

AndreasLokko avatar Mar 11 '24 11:03 AndreasLokko

Verified the above PR solves the issue. Thanks!

GomesGoncalo avatar Apr 04 '24 03:04 GomesGoncalo