Skip to content

Commit 0da93f3

Browse files
committed
goto-cc: Replace assert(...) by macros from invariant.h
While new/modified code shouldn't use assert(...) anyway, we had several existing uses of assert. Once we remove nonstd/optional.h, we will no longer implicitly include cassert, implying that a lot of #include <cassert> changes will be necessary. Instead of adding these, go all the way and fix the undesired uses of assert.
1 parent 55b2039 commit 0da93f3

File tree

6 files changed

+23
-18
lines changed

6 files changed

+23
-18
lines changed

src/goto-cc/as86_cmdline.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Author: Michael Tautschnig
1111

1212
#include "as86_cmdline.h"
1313

14-
#include <iostream>
15-
14+
#include <util/invariant.h>
1615
#include <util/prefix.h>
1716

17+
#include <iostream>
18+
1819
// non-as86 options
1920
const char *goto_as86_options_with_argument[]=
2021
{
@@ -56,7 +57,7 @@ const char *as86_options_with_argument[]=
5657

5758
bool as86_cmdlinet::parse(int argc, const char **argv)
5859
{
59-
assert(argc>0);
60+
PRECONDITION(argc > 0);
6061
add_arg(argv[0]);
6162

6263
for(int i=1; i<argc; i++)

src/goto-cc/as_cmdline.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Author: Michael Tautschnig
1111

1212
#include "as_cmdline.h"
1313

14-
#include <iostream>
15-
14+
#include <util/invariant.h>
1615
#include <util/prefix.h>
1716

17+
#include <iostream>
18+
1819
// non-as options
1920
const char *goto_as_options_with_argument[]=
2021
{
@@ -78,7 +79,7 @@ const char *as_options_with_argument[]=
7879

7980
bool as_cmdlinet::parse(int argc, const char **argv)
8081
{
81-
assert(argc>0);
82+
PRECONDITION(argc > 0);
8283
add_arg(argv[0]);
8384

8485
for(int i=1; i<argc; i++)

src/goto-cc/as_mode.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ int as_modet::doit()
201201
{
202202
if(outputs>0)
203203
{
204-
assert(!dest.empty());
204+
PRECONDITION(!dest.empty());
205205
compiler.add_input_file(dest);
206206
os.close();
207207
}
@@ -230,7 +230,7 @@ int as_modet::doit()
230230

231231
if(outputs>0)
232232
{
233-
assert(!dest.empty());
233+
PRECONDITION(!dest.empty());
234234
compiler.add_input_file(dest);
235235
}
236236
else
@@ -260,7 +260,7 @@ int as_modet::doit()
260260
/// run as or as86 with original command line
261261
int as_modet::run_as()
262262
{
263-
assert(!cmdline.parsed_argv.empty());
263+
PRECONDITION(!cmdline.parsed_argv.empty());
264264

265265
// build new argv
266266
std::vector<std::string> new_argv;

src/goto-cc/bcc_cmdline.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Author: Michael Tautschnig
1111

1212
#include "bcc_cmdline.h"
1313

14-
#include <iostream>
15-
14+
#include <util/invariant.h>
1615
#include <util/prefix.h>
1716

17+
#include <iostream>
18+
1819
// non-bcc options
1920
const char *goto_bcc_options_with_argument[]=
2021
{
@@ -68,7 +69,7 @@ const char *bcc_options_with_argument[]=
6869

6970
bool bcc_cmdlinet::parse(int argc, const char **argv)
7071
{
71-
assert(argc>0);
72+
PRECONDITION(argc > 0);
7273
add_arg(argv[0]);
7374

7475
for(int i=1; i<argc; i++)

src/goto-cc/gcc_cmdline.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Author: CM Wintersteiger, 2006
1111

1212
#include "gcc_cmdline.h"
1313

14+
#include <util/invariant.h>
1415
#include <util/prefix.h>
1516

1617
#include <cstring>
@@ -228,7 +229,7 @@ const char *gcc_options_without_argument[]=
228229
/// \return none
229230
bool gcc_cmdlinet::parse(int argc, const char **argv)
230231
{
231-
assert(argc>0);
232+
PRECONDITION(argc > 0);
232233
add_arg(argv[0]);
233234

234235
argst current_args;
@@ -447,8 +448,8 @@ bool gcc_cmdlinet::parse_arguments(
447448
void gcc_cmdlinet::parse_specs_line(const std::string &line, bool in_spec_file)
448449
{
449450
// initial whitespace has been stripped
450-
assert(!line.empty());
451-
assert(line[0]!=' ' && line[0]!='\t');
451+
PRECONDITION(!line.empty());
452+
PRECONDITION(line[0] != ' ' && line[0] != '\t');
452453

453454
argst args_from_specs;
454455

src/goto-cc/ld_cmdline.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@ Author: Daniel Kroening, 2013
1111

1212
#include "ld_cmdline.h"
1313

14-
#include <iostream>
15-
14+
#include <util/invariant.h>
1615
#include <util/prefix.h>
1716

17+
#include <iostream>
18+
1819
// clang-format off
1920
const char *goto_ld_options_with_argument[]=
2021
{
@@ -253,7 +254,7 @@ const char *ld_options_without_argument[]=
253254
/// \return none
254255
bool ld_cmdlinet::parse(int argc, const char **argv)
255256
{
256-
assert(argc>0);
257+
PRECONDITION(argc > 0);
257258
add_arg(argv[0]);
258259

259260
for(int i=1; i<argc; i++)

0 commit comments

Comments
 (0)