You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by GitBox <gi...@apache.org> on 2020/09/24 17:25:35 UTC

[GitHub] [trafficserver] SolidWallOfCode commented on a change in pull request #5846: Switch to better TS-specific assert macros.

SolidWallOfCode commented on a change in pull request #5846:
URL: https://github.com/apache/trafficserver/pull/5846#discussion_r494487993



##########
File path: include/tscore/ts_assert.h
##########
@@ -0,0 +1,53 @@
+/** @file
+
+  A brief file description
+
+  @section license License
+
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+      http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+ */
+
+#pragma once
+
+#include "tscore/ink_assert.h"
+
+/*
+TS_RELEASE_ASSERT expands to a void-type expression.  It causes the program to abort if an expression EXPR of
+type bool (or of a type that implictly converts to bool) is false.
+*/
+#define TS_RELEASE_ASSERT(EXPR) ((EXPR) ? static_cast<void>(0) : _ink_assert(#EXPR, __FILE__, __LINE__))
+
+/*
+TS_ASSERT/TS_ASSERT_NSE expand to void-type expressions.  They cause the program to abort, in a non-relaase or
+otherwise non-optimized executable, if an expression EXPR of type bool (or of a type that implictly converts to
+bool) is false.  For TS_ASSERT, side-effects of EXPR will still occur even in a non-optimized executable.  For
+TS_ASSERT_NSE (NSE = no side effects), side-effects of EXPR will not occur, in a non-optimized executable.
+*/
+
+// __OPTIMIZE__ is defined by both gcc and clang/LLVM if optimization level is 1 or higher.
+//
+#if defined(__OPTIMIZE__)
+
+#define TS_ASSERT(EXPR) static_cast<void>(EXPR)
+#define TS_ASSERT_NSE(EXPR) static_cast<void>(0)

Review comment:
       There are, unfortunately, many cases where side effects are inside asserts. I think that's a terrible thing to do, but I see PRs even now that are adding code with such side effect asserts and I was brushed backed when I objected to it.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org