Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Constructor attribute is only working correctly in gcc #590

Closed
GomesGoncalo opened this issue Oct 14, 2023 · 3 comments
Closed

Constructor attribute is only working correctly in gcc #590

GomesGoncalo opened this issue Oct 14, 2023 · 3 comments

Comments

@GomesGoncalo
Copy link

GomesGoncalo commented Oct 14, 2023

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 6a3d4c1)
  • 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
@jhasse
Copy link

jhasse commented Dec 12, 2023

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

@AndreasLokko
Copy link
Contributor

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

@GomesGoncalo
Copy link
Author

Verified the above PR solves the issue. Thanks!

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

No branches or pull requests

3 participants