compiler_diagnostics.h Source File

CPP API: compiler_diagnostics.h Source File
compiler_diagnostics.h
Go to the documentation of this file.
1 /*
2 * Copyright (C) 2020-2026 MEmilio
3 *
4 * Authors: Daniel Abele
5 *
6 * Contact: Martin J. Kuehn <Martin.Kuehn@DLR.de>
7 *
8 * Licensed under the Apache License, Version 2.0 (the "License");
9 * you may not use this file except in compliance with the License.
10 * You may obtain a copy of the License at
11 *
12 * http://www.apache.org/licenses/LICENSE-2.0
13 *
14 * Unless required by applicable law or agreed to in writing, software
15 * distributed under the License is distributed on an "AS IS" BASIS,
16 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17 * See the License for the specific language governing permissions and
18 * limitations under the License.
19 */
20 #ifndef MIO_UTILS_COMPILER_DIAGNOSTICS_H
21 #define MIO_UTILS_COMPILER_DIAGNOSTICS_H
22 
23 namespace mio
24 {
29 template <class... T>
30 void unused(T&&...)
31 {
32 }
33 
34 } // namespace mio
35 
36 #define QUOTE(x) #x
37 
38 //defines warning macros for MSVC
39 #ifdef _MSC_VER
40 #define MSVC_WARNING_DISABLE_PUSH(list) __pragma(warning(push)) __pragma(warning(disable : list))
41 #define MSVC_WARNING_POP() __pragma(warning(pop))
42 #else
43 #define MSVC_WARNING_DISABLE_PUSH(...)
44 #define MSVC_WARNING_POP()
45 #endif
46 
47 //defines warning macros for gcc and clang
48 #if defined(__GNUC__) || defined(__clang__)
49 
50 #ifdef __GNUC__
51 #define COMPILER GCC
52 #else
53 #define COMPILER clang
54 #endif
55 
56 //there's probably a way to disable multiple warnings in one macro with __VA_ARGS__
57 #define GCC_CLANG_DIAGNOSTIC_(x) _Pragma(QUOTE(x))
58 #define GCC_CLANG_DIAGNOSTIC(x) GCC_CLANG_DIAGNOSTIC_(COMPILER diagnostic x)
59 
60 #else //gcc, clang
61 
62 #define GCC_CLANG_DIAGNOSTIC(...)
63 
64 #endif //gcc, clang
65 
66 //MSVC has a long standing bug that breaks empty base optimization (EBO)
67 //if the class has more than one empty base class.
68 //types that rely on empty base optimization must add this declaration
69 //e.g. struct MEMILIO_ENABLE_EBO Foo : EmptyBase1, EmptyBase2, ...
70 //see https://en.cppreference.com/w/cpp/language/ebo
71 //see https://stackoverflow.com/questions/12701469/why-is-the-empty-base-class-optimization-ebo-is-not-working-in-msvc
72 #ifdef _MSC_VER
73 #define MEMILIO_ENABLE_EBO __declspec(empty_bases)
74 #else
75 #define MEMILIO_ENABLE_EBO
76 #endif
77 
78 #endif // MIO_UTILS_COMPILER_DIAGNOSTICS_H
A collection of classes to simplify handling of matrix shapes in meta programming.
Definition: models/abm/analyze_result.h:30
void unused(T &&...)
Does nothing, can be used to mark variables as not used.
Definition: compiler_diagnostics.h:30