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

fix(debug): add missing parentheses in ternary expression #1035

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
cmake_minimum_required (VERSION 3.21)
cmake_minimum_required (VERSION 3.22)
project (glog
VERSION 0.7.0
DESCRIPTION "C++ implementation of the Google logging module"
Expand Down Expand Up @@ -908,6 +908,51 @@ if (BUILD_TESTING)
-DCMAKE_GENERATOR_TOOLSET=${CMAKE_GENERATOR_TOOLSET}
-Dglog_DIR=${glog_BINARY_DIR}
)

add_test (NAME dcheck_on COMMAND ${CMAKE_CTEST_COMMAND}
--build-config Debug
--build-and-test
"${glog_SOURCE_DIR}/src/dcheck_unittest"
"${glog_BINARY_DIR}/Tests/dcheck_on"
--build-generator ${CMAKE_GENERATOR}
--build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
--build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-target glog_dcheck
--build-options
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON
-Dglog_DIR=${glog_BINARY_DIR}
--test-command glog_dcheck
)
set_tests_properties (dcheck_on PROPERTIES
DISABLED $<NOT:$<CONFIG:Debug,RelWithDebInfo>>
ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:glog>"
PASS_REGULAR_EXPRESSION "Assert failed: false"
)

add_test (NAME dcheck_off COMMAND ${CMAKE_CTEST_COMMAND}
--build-config Release
--build-and-test
"${glog_SOURCE_DIR}/src/dcheck_unittest"
"${glog_BINARY_DIR}/Tests/dcheck_off"
--build-generator ${CMAKE_GENERATOR}
--build-generator-platform "${CMAKE_GENERATOR_PLATFORM}"
--build-generator-toolset "${CMAKE_GENERATOR_TOOLSET}"
--build-makeprogram ${CMAKE_MAKE_PROGRAM}
--build-target glog_dcheck
--build-options
-DCMAKE_CXX_COMPILER=${CMAKE_CXX_COMPILER}
-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON
-Dglog_DIR=${glog_BINARY_DIR}
--test-command glog_dcheck
)
# There should be no output
set_tests_properties (dcheck_off PROPERTIES
DISABLED $<NOT:$<CONFIG:Release,MinSizeRel>>
ENVIRONMENT_MODIFICATION "PATH=path_list_prepend:$<TARGET_FILE_DIR:glog>"
PASS_REGULAR_EXPRESSION ""
)
endif (BUILD_TESTING)

install (TARGETS glog
Expand Down
7 changes: 7 additions & 0 deletions src/dcheck_unittest/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required (VERSION 3.16)
project (glog_log_severity LANGUAGES CXX)

find_package (glog REQUIRED NO_MODULE)

add_executable (glog_dcheck glog_dcheck.cc)
target_link_libraries (glog_dcheck PRIVATE glog::glog)
53 changes: 53 additions & 0 deletions src/dcheck_unittest/glog_dcheck.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// Copyright (c) 2024, Google Inc.
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
//
// Author: Sergiu Deitsch

#include <glog/logging.h>

int main(int /*argc*/, char** argv) {
google::InitGoogleLogging(argv[0]);
google::InstallFailureSignalHandler();

#if defined(_MSC_VER)
// Avoid presenting an interactive dialog that will cause the test to time
// out.
_set_abort_behavior(0, _WRITE_ABORT_MSG | _CALL_REPORTFAULT);
#endif // defined(_MSC_VER)

DLOG(INFO) << "no output";
DLOG(WARNING) << "no output";
DLOG(ERROR) << "no output";

// Must not fail in release build
DLOG_ASSERT(false);

// Must be the last expression
DLOG(FATAL) << "no output";
}
2 changes: 1 addition & 1 deletion src/glog/logging.h
Original file line number Diff line number Diff line change
Expand Up @@ -1070,7 +1070,7 @@ constexpr LogSeverity GLOG_0 = GLOG_ERROR;
true ? (void)0 : google::LogMessageVoidify() & LOG(severity)

# define DLOG_ASSERT(condition) \
static_cast<void>(0), true ? (void)0 : LOG_ASSERT(condition)
static_cast<void>(0), true ? (void)0 : (LOG_ASSERT(condition))

// MSVC warning C4127: conditional expression is constant
# define DCHECK(condition) \
Expand Down
Loading