Skip to content

GTEST_AMBIGUOUS_ELSE_BLOCKER_ does not block the warning for gcc-7.1. #1119

Closed
@gkistanova

Description

@gkistanova

Starting from gcc 7.1 the GTEST_ASSERT_ and all the dependencies produce the following warning,
when used with if statement without surrounding braces.

It seems GTEST_AMBIGUOUS_ELSE_BLOCKER_ does not do the trick any more.

To reproduce, compile the following code

// gtest-ambiguous-else-warning.cpp
#include "gtest/gtest.h"

void foo(int i) {
  if (i > 0)
    GTEST_ASSERT_(::testing::AssertionFailure(), GTEST_NONFATAL_FAILURE_);
}

with

gcc-7.1 -Wall -c ./gtest-ambiguous-else-warning.cpp

The printout would be

./gtest-ambiguous-else-warning.cpp: In function 'void foo(int)':
./gtest-ambiguous-else-warning:4:6: warning: suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]
   if (i > 0)
      ^

We observe the issue with Google Test 1.8.0, but as far as I can tell, it is the same in the current trunk.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions