1// Copyright 2023 The Chromium Authors 2// Use of this source code is governed by a BSD-style license that can be 3// found in the LICENSE file. 4 5// This is a "No Compile Test" suite. 6// https://dev.chromium.org/developers/testing/no-compile-tests 7 8#include "base/logging.h" 9 10// LOG(FATAL) must be understood as [[noreturn]]. 11int Foo() { 12 LOG(FATAL) << "I am [[noreturn]]!"; 13 return 42; // expected-error {{'return' will never be executed}} 14} 15 16int Foo2() { 17 LOG_ASSERT(false) << "I am [[noreturn]] (sometimes)!"; 18 return 42; // expected-error {{'return' will never be executed}} 19} 20 21// It's important that our logging macros agree on [[noreturn]] in all build 22// configurations (or dead-code warnings become impossible to satisfy). As such 23// neither LOG(DFATAL) or DLOG(FATAL) may be understood as [[noreturn]]. This 24// non-void function not returning a value after LOG(DFATAL) and DLOG(FATAL) 25// should always be a compile error due to a missing return statement. 26int Bar() { 27 // No LOG(DFATAL) macros should be understood as [[noreturn]] under any build 28 // configurations. 29 LOG(DFATAL) << "I am not [[noreturn]]!"; 30 LOG_IF(DFATAL, true) << "I am not [[noreturn]]!"; 31 PLOG(DFATAL) << "I am not [[noreturn]]!"; 32 PLOG_IF(DFATAL, true) << "I am not [[noreturn]]!"; 33 34 // Same as above but DLOG(FATAL) instead of LOG(DFATAL). 35 DLOG(FATAL) << "I am not [[noreturn]]!"; 36 DLOG_IF(FATAL, true) << "I am not [[noreturn]]!"; 37 DPLOG(FATAL) << "I am not [[noreturn]]!"; 38 DPLOG_IF(FATAL, true) << "I am not [[noreturn]]!"; 39 DLOG_ASSERT(false) << "I am not [[noreturn]]!"; 40} // expected-error {{non-void function does not return a value}} 41