Bug Summary

File:conftest.cpp
Warning:line 190, column 8
Value stored to 'b' during its initialization is never read

Annotated Source Code

Press '?' to see keyboard shortcuts

clang -cc1 -cc1 -triple x86_64-pc-linux-gnu -analyze -disable-free -clear-ast-before-backend -disable-llvm-verifier -discard-value-names -main-file-name conftest.cpp -analyzer-checker=core -analyzer-checker=apiModeling -analyzer-checker=unix -analyzer-checker=deadcode -analyzer-checker=cplusplus -analyzer-checker=security.insecureAPI.UncheckedReturn -analyzer-checker=security.insecureAPI.getpw -analyzer-checker=security.insecureAPI.gets -analyzer-checker=security.insecureAPI.mktemp -analyzer-checker=security.insecureAPI.mkstemp -analyzer-checker=security.insecureAPI.vfork -analyzer-checker=nullability.NullPassedToNonnull -analyzer-checker=nullability.NullReturnedFromNonnull -analyzer-output plist -w -setup-static-analyzer -mrelocation-model pic -pic-level 2 -pic-is-pie -mframe-pointer=none -fmath-errno -ffp-contract=on -fno-rounding-math -mconstructor-aliases -funwind-tables=2 -target-cpu x86-64 -tune-cpu generic -debugger-tuning=gdb -fcoverage-compilation-dir=/tmp/build/hfst/hfst-3.16.0+g3891~5c3a0833 -resource-dir /usr/lib/llvm-16/lib/clang/16 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/x86_64-linux-gnu/c++/14 -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../include/c++/14/backward -internal-isystem /usr/lib/llvm-16/lib/clang/16/include -internal-isystem /usr/local/include -internal-isystem /usr/lib/gcc/x86_64-linux-gnu/14/../../../../x86_64-linux-gnu/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -O2 -fdeprecated-macro -fdebug-compilation-dir=/tmp/build/hfst/hfst-3.16.0+g3891~5c3a0833 -ferror-limit 19 -fgnuc-version=4.2.1 -fcxx-exceptions -fexceptions -vectorize-loops -vectorize-slp -analyzer-output=html -faddrsig -D__GCC_HAVE_DWARF2_CFI_ASM=1 -o /tmp/build/hfst/scan-build/2024-09-11-140418-74542-1 -x c++ conftest.cpp
1/* confdefs.h */
2#define PACKAGE_NAME"hfst" "hfst"
3#define PACKAGE_TARNAME"hfst" "hfst"
4#define PACKAGE_VERSION"3.16.0" "3.16.0"
5#define PACKAGE_STRING"hfst 3.16.0" "hfst 3.16.0"
6#define PACKAGE_BUGREPORT"hfst-bugs@helsinki.fi" "hfst-bugs@helsinki.fi"
7#define PACKAGE_URL"" ""
8#define PACKAGE"hfst" "hfst"
9#define VERSION"3.16.0" "3.16.0"
10#define HFST_LONGVERSION300160000L 300160000L
11#define HFST_REVISION"$Revision$" "$Revision$"
12#define HFST_STRING"hfst 3.16.0" "hfst 3.16.0"
13#define HAVE_SFST1 1
14#define HAVE_OPENFST1 1
15#define HAVE_OPENFST_LOG1 1
16#define HAVE_FOMA1 1
17#define HAVE_STDIO_H1 1
18#define HAVE_STDLIB_H1 1
19#define HAVE_STRING_H1 1
20#define HAVE_INTTYPES_H1 1
21#define HAVE_STDINT_H1 1
22#define HAVE_STRINGS_H1 1
23#define HAVE_SYS_STAT_H1 1
24#define HAVE_SYS_TYPES_H1 1
25#define HAVE_UNISTD_H1 1
26#define STDC_HEADERS1 1
27#define HAVE_HFSTOL1 1
28#define ENABLE_LOAD_SO_ENTRIES1 1
29/* end confdefs.h. */
30
31// Does the compiler advertise C++98 conformance?
32#if !defined __cplusplus201703L || __cplusplus201703L < 199711L
33# error "Compiler does not advertise C++98 conformance"
34#endif
35
36// These inclusions are to reject old compilers that
37// lack the unsuffixed header files.
38#include <cstdlib>
39#include <exception>
40
41// <cassert> and <cstring> are *not* freestanding headers in C++98.
42extern void assert (int);
43namespace std {
44 extern int strcmp (const char *, const char *);
45}
46
47// Namespaces, exceptions, and templates were all added after "C++ 2.0".
48using std::exception;
49using std::strcmp;
50
51namespace {
52
53void test_exception_syntax()
54{
55 try {
56 throw "test";
57 } catch (const char *s) {
58 // Extra parentheses suppress a warning when building autoconf itself,
59 // due to lint rules shared with more typical C programs.
60 assert (!(strcmp) (s, "test"));
61 }
62}
63
64template <typename T> struct test_template
65{
66 T const val;
67 explicit test_template(T t) : val(t) {}
68 template <typename U> T add(U u) { return static_cast<T>(u) + val; }
69};
70
71} // anonymous namespace
72
73
74// Does the compiler advertise C++ 2011 conformance?
75#if !defined __cplusplus201703L || __cplusplus201703L < 201103L
76# error "Compiler does not advertise C++11 conformance"
77#endif
78
79namespace cxx11test
80{
81 constexpr int get_val() { return 20; }
82
83 struct testinit
84 {
85 int i;
86 double d;
87 };
88
89 class delegate
90 {
91 public:
92 delegate(int n) : n(n) {}
93 delegate(): delegate(2354) {}
94
95 virtual int getval() { return this->n; };
96 protected:
97 int n;
98 };
99
100 class overridden : public delegate
101 {
102 public:
103 overridden(int n): delegate(n) {}
104 virtual int getval() override final { return this->n * 2; }
105 };
106
107 class nocopy
108 {
109 public:
110 nocopy(int i): i(i) {}
111 nocopy() = default;
112 nocopy(const nocopy&) = delete;
113 nocopy & operator=(const nocopy&) = delete;
114 private:
115 int i;
116 };
117
118 // for testing lambda expressions
119 template <typename Ret, typename Fn> Ret eval(Fn f, Ret v)
120 {
121 return f(v);
122 }
123
124 // for testing variadic templates and trailing return types
125 template <typename V> auto sum(V first) -> V
126 {
127 return first;
128 }
129 template <typename V, typename... Args> auto sum(V first, Args... rest) -> V
130 {
131 return first + sum(rest...);
132 }
133}
134
135
136int
137main (int argc, char **argv)
138{
139 int ok = 0;
140
141 assert (argc);
142 assert (! argv[0]);
143{
144 test_exception_syntax ();
145 test_template<double> tt (2.0);
146 assert (tt.add (4) == 6.0);
147 assert (true && !false);
148}
149
150
151{
152 // Test auto and decltype
153 auto a1 = 6538;
154 auto a2 = 48573953.4;
155 auto a3 = "String literal";
156
157 int total = 0;
158 for (auto i = a3; *i; ++i) { total += *i; }
159
160 decltype(a2) a4 = 34895.034;
161}
162{
163 // Test constexpr
164 short sa[cxx11test::get_val()] = { 0 };
165}
166{
167 // Test initializer lists
168 cxx11test::testinit il = { 4323, 435234.23544 };
169}
170{
171 // Test range-based for
172 int array[] = {9, 7, 13, 15, 4, 18, 12, 10, 5, 3,
173 14, 19, 17, 8, 6, 20, 16, 2, 11, 1};
174 for (auto &x : array) { x += 23; }
175}
176{
177 // Test lambda expressions
178 using cxx11test::eval;
179 assert (eval ([](int x) { return x*2; }, 21) == 42);
180 double d = 2.0;
181 assert (eval ([&](double x) { return d += x; }, 3.0) == 5.0);
182 assert (d == 5.0);
183 assert (eval ([=](double x) mutable { return d += x; }, 4.0) == 9.0);
184 assert (d == 5.0);
185}
186{
187 // Test use of variadic templates
188 using cxx11test::sum;
189 auto a = sum(1);
190 auto b = sum(1, 2);
Value stored to 'b' during its initialization is never read
191 auto c = sum(1.0, 2.0, 3.0);
192}
193{
194 // Test constructor delegation
195 cxx11test::delegate d1;
196 cxx11test::delegate d2();
197 cxx11test::delegate d3(45);
198}
199{
200 // Test override and final
201 cxx11test::overridden o1(55464);
202}
203{
204 // Test nullptr
205 char *c = nullptr;
206}
207{
208 // Test template brackets
209 test_template<::test_template<int>> v(test_template<int>(12));
210}
211{
212 // Unicode literals
213 char const *utf8 = u8"UTF-8 string \u2500";
214 char16_t const *utf16 = u"UTF-8 string \u2500";
215 char32_t const *utf32 = U"UTF-32 string \u2500";
216}
217
218 return ok;
219}
220