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

INFO() generates -Wextra-semi-stmt with clang++-latest #1456

Closed
AndrewPaxie opened this issue Nov 25, 2018 · 0 comments
Closed

INFO() generates -Wextra-semi-stmt with clang++-latest #1456

AndrewPaxie opened this issue Nov 25, 2018 · 0 comments
Milestone

Comments

@AndrewPaxie
Copy link

Description

Compile the unit tests for the Trompeloeil mock object library.

Expected result: The unit tests compile without warnings or errors.

Actual result: The compilation completes with this warning message,

test/compiling_tests_11.cpp:245:24:
warning: empty expression statement has no effect;
remove unnecessary ';' to silence this warning [-Wextra-semi-stmt]
    INFO("msg=" << msg);
                       ^

63 warnings of this kind total.

Other combinations of C++ Standard Library implementation
also generate the warning. So too does previous versions of Catch
e.g. version 2.2.3.

Steps to reproduce

Minimal program to reproduce issue:

#include <catch.hpp>

TEST_CASE("Foo")
{
    INFO("Test case start");
}

Compile with Clang latest (i.e. with at least commit
0d4609da69d513b7737d2f932e3db6e57f7b11c3).

Command line contains either

-Weverything \
-Wno-pragma-system-header-outside-header \
-Wno-c++98-compat \
-Wno-c++98-compat-pedantic \
-Wno-unused-macros

or

-Wno-pragma-system-header-outside-header \
-Wextra-semi-stmt

Godbolt: https://godbolt.org/z/Y9wR08

Extra information

Operating system: Ubuntu 18.10 (Cosmic Cuttlefish)
Compiler: clang++-latest (compiled from trunk)
Standard C++ Library: libstdc++-v3 (e.g. from G++ 8.2.0)
Catch version: v2.4.2 (other versions also exhibit issue)

See also: rollbear/trompeloeil#107.

Supposed cause

Clang latest began generating this warning with this commit

commit 0d4609da69d513b7737d2f932e3db6e57f7b11c3
Author: Roman Lebedev <lebedev.ri@gmail.com>
Date:   Tue Nov 20 18:59:05 2018 +0000

:::

    Fixes [[ https://bugs.llvm.org/show_bug.cgi?id=39111 | PR39111 ]]

:::

The issue is with Catch2: WARN and CAPTURE macros expect a semicolon
to terminate them (see INTERNAL_CATCH_MSG, INTERNAL_CATCH_CAPTURE).
INFO forwards to INTERNAL_CATCH_INFO which has a trailing semicolon.

The examples in the Catch documentation are also inconsistent, with semicolon
terminating INFO in some examples and no semicolon terminating INFO in
other examples.

Suggested fix

Remove the trailing semicolon from INTERNAL_CATCH_INFO.

Update the documentation to consistently have a semicolon
at the end of each use of the INFO macro.

Advise Catch users that their code may no longer compile if they
leave the trailing semicolon off their INFO macros.

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

No branches or pull requests

3 participants