Skip to content

Commit 0ff0149

Browse files
authored
Fix danmar#449 (Update c++ standard to c++11) (danmar#450)
1 parent 8f8bfe3 commit 0ff0149

File tree

5 files changed

+19
-119
lines changed

5 files changed

+19
-119
lines changed

.github/workflows/clang-tidy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ jobs:
3030
3131
- name: Prepare CMake
3232
run: |
33-
cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON -DDISABLE_CPP03_SYNTAX_CHECK=ON
33+
cmake -S . -B cmake.output -G "Unix Makefiles" -DCMAKE_EXPORT_COMPILE_COMMANDS=ON
3434
env:
3535
CXX: clang-20
3636

CMakeLists.txt

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
cmake_minimum_required (VERSION 3.10)
22
project (simplecpp LANGUAGES CXX)
33

4-
option(DISABLE_CPP03_SYNTAX_CHECK "Disable the C++03 syntax check." OFF)
4+
set(CMAKE_CXX_STANDARD 11)
5+
set(CMAKE_CXX_STANDARD_REQUIRED ON)
56

67
include(CheckCXXCompilerFlag)
78

@@ -70,25 +71,7 @@ endif()
7071
add_library(simplecpp_obj OBJECT simplecpp.cpp)
7172

7273
add_executable(simplecpp $<TARGET_OBJECTS:simplecpp_obj> main.cpp)
73-
set_property(TARGET simplecpp PROPERTY CXX_STANDARD 11)
74-
75-
if (NOT DISABLE_CPP03_SYNTAX_CHECK)
76-
# it is not possible to set a standard older than C++14 with Visual Studio
77-
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU" OR CMAKE_CXX_COMPILER_ID MATCHES "Clang")
78-
# we need to create a dummy library as -fsyntax-only will not produce any output files causing the build to fail
79-
add_library(simplecpp-03-syntax OBJECT simplecpp.cpp)
80-
target_compile_options(simplecpp-03-syntax PRIVATE -std=c++03)
81-
if (CMAKE_CXX_COMPILER_ID MATCHES "GNU")
82-
target_compile_options(simplecpp-03-syntax PRIVATE -Wno-long-long)
83-
elseif (CMAKE_CXX_COMPILER_ID MATCHES "Clang")
84-
target_compile_options(simplecpp-03-syntax PRIVATE -Wno-c++11-long-long -Wno-c++11-compat)
85-
endif()
86-
add_dependencies(simplecpp simplecpp-03-syntax)
87-
endif()
88-
endif()
89-
9074
add_executable(testrunner $<TARGET_OBJECTS:simplecpp_obj> test.cpp)
91-
set_property(TARGET testrunner PROPERTY CXX_STANDARD 11)
9275

9376
enable_testing()
9477
add_test(NAME testrunner COMMAND testrunner)

Makefile

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
all: testrunner simplecpp
22

3-
CXXFLAGS = -Wall -Wextra -pedantic -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wredundant-decls -Wundef -Wno-multichar -Wold-style-cast -std=c++0x -g
3+
CXXFLAGS = -Wall -Wextra -pedantic -Wcast-qual -Wfloat-equal -Wmissing-declarations -Wmissing-format-attribute -Wredundant-decls -Wundef -Wno-multichar -Wold-style-cast -std=c++11 -g
44
LDFLAGS = -g
55

66
%.o: %.cpp simplecpp.h
@@ -11,8 +11,6 @@ testrunner: test.o simplecpp.o
1111
$(CXX) $(LDFLAGS) simplecpp.o test.o -o testrunner
1212

1313
test: testrunner simplecpp
14-
# The -std=c++03 makes sure that simplecpp.cpp is C++03 conformant. We don't require a C++11 compiler
15-
g++ -std=c++03 -fsyntax-only simplecpp.cpp
1614
./testrunner
1715
python3 run-tests.py
1816

simplecpp.cpp

Lines changed: 15 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -31,12 +31,10 @@
3131
#include <stack>
3232
#include <stdexcept>
3333
#include <string>
34-
#if __cplusplus >= 201103L
3534
#ifdef SIMPLECPP_WINDOWS
3635
#include <mutex>
3736
#endif
3837
#include <unordered_map>
39-
#endif
4038
#include <utility>
4139
#include <vector>
4240

@@ -51,18 +49,6 @@
5149
#undef ERROR
5250
#endif
5351

54-
#if __cplusplus >= 201103L
55-
#define OVERRIDE override
56-
#define EXPLICIT explicit
57-
#else
58-
#define OVERRIDE
59-
#define EXPLICIT
60-
#endif
61-
62-
#if (__cplusplus < 201103L) && !defined(__APPLE__)
63-
#define nullptr NULL
64-
#endif
65-
6652
static bool isHex(const std::string &s)
6753
{
6854
return s.size()>2 && (s.compare(0,2,"0x")==0 || s.compare(0,2,"0X")==0);
@@ -368,22 +354,22 @@ class simplecpp::TokenList::Stream {
368354
class StdIStream : public simplecpp::TokenList::Stream {
369355
public:
370356
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
371-
EXPLICIT StdIStream(std::istream &istr)
357+
explicit StdIStream(std::istream &istr)
372358
: istr(istr) {
373359
assert(istr.good());
374360
init();
375361
}
376362

377-
virtual int get() OVERRIDE {
363+
virtual int get() override {
378364
return istr.get();
379365
}
380-
virtual int peek() OVERRIDE {
366+
virtual int peek() override {
381367
return istr.peek();
382368
}
383-
virtual void unget() OVERRIDE {
369+
virtual void unget() override {
384370
istr.unget();
385371
}
386-
virtual bool good() OVERRIDE {
372+
virtual bool good() override {
387373
return istr.good();
388374
}
389375

@@ -402,20 +388,20 @@ class StdCharBufStream : public simplecpp::TokenList::Stream {
402388
init();
403389
}
404390

405-
virtual int get() OVERRIDE {
391+
virtual int get() override {
406392
if (pos >= size)
407393
return lastStatus = EOF;
408394
return str[pos++];
409395
}
410-
virtual int peek() OVERRIDE {
396+
virtual int peek() override {
411397
if (pos >= size)
412398
return lastStatus = EOF;
413399
return str[pos];
414400
}
415-
virtual void unget() OVERRIDE {
401+
virtual void unget() override {
416402
--pos;
417403
}
418-
virtual bool good() OVERRIDE {
404+
virtual bool good() override {
419405
return lastStatus != EOF;
420406
}
421407

@@ -429,7 +415,7 @@ class StdCharBufStream : public simplecpp::TokenList::Stream {
429415
class FileStream : public simplecpp::TokenList::Stream {
430416
public:
431417
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
432-
EXPLICIT FileStream(const std::string &filename, std::vector<std::string> &files)
418+
explicit FileStream(const std::string &filename, std::vector<std::string> &files)
433419
: file(fopen(filename.c_str(), "rb"))
434420
, lastCh(0)
435421
, lastStatus(0) {
@@ -440,25 +426,25 @@ class FileStream : public simplecpp::TokenList::Stream {
440426
init();
441427
}
442428

443-
~FileStream() OVERRIDE {
429+
~FileStream() override {
444430
fclose(file);
445431
file = nullptr;
446432
}
447433

448-
virtual int get() OVERRIDE {
434+
virtual int get() override {
449435
lastStatus = lastCh = fgetc(file);
450436
return lastCh;
451437
}
452-
virtual int peek() OVERRIDE{
438+
virtual int peek() override{
453439
// keep lastCh intact
454440
const int ch = fgetc(file);
455441
unget_internal(ch);
456442
return ch;
457443
}
458-
virtual void unget() OVERRIDE {
444+
virtual void unget() override {
459445
unget_internal(lastCh);
460446
}
461-
virtual bool good() OVERRIDE {
447+
virtual bool good() override {
462448
return lastStatus != EOF;
463449
}
464450

@@ -519,12 +505,10 @@ simplecpp::TokenList::TokenList(const TokenList &other) : frontToken(nullptr), b
519505
*this = other;
520506
}
521507

522-
#if __cplusplus >= 201103L
523508
simplecpp::TokenList::TokenList(TokenList &&other) : frontToken(nullptr), backToken(nullptr), files(other.files)
524509
{
525510
*this = std::move(other);
526511
}
527-
#endif
528512

529513
simplecpp::TokenList::~TokenList()
530514
{
@@ -543,7 +527,6 @@ simplecpp::TokenList &simplecpp::TokenList::operator=(const TokenList &other)
543527
return *this;
544528
}
545529

546-
#if __cplusplus >= 201103L
547530
simplecpp::TokenList &simplecpp::TokenList::operator=(TokenList &&other)
548531
{
549532
if (this != &other) {
@@ -557,7 +540,6 @@ simplecpp::TokenList &simplecpp::TokenList::operator=(TokenList &&other)
557540
}
558541
return *this;
559542
}
560-
#endif
561543

562544
void simplecpp::TokenList::clear()
563545
{
@@ -1477,11 +1459,7 @@ unsigned int simplecpp::TokenList::fileIndex(const std::string &filename)
14771459

14781460
namespace simplecpp {
14791461
class Macro;
1480-
#if __cplusplus >= 201103L
14811462
using MacroMap = std::unordered_map<TokenString,Macro>;
1482-
#else
1483-
typedef std::map<TokenString,Macro> MacroMap;
1484-
#endif
14851463

14861464
class Macro {
14871465
public:
@@ -1791,13 +1769,8 @@ namespace simplecpp {
17911769
tok = tok->next;
17921770
}
17931771
}
1794-
#if __cplusplus >= 201103L
17951772
optExpandValue = new TokenList(std::move(expandValue));
17961773
optNoExpandValue = new TokenList(std::move(noExpandValue));
1797-
#else
1798-
optExpandValue = new TokenList(expandValue);
1799-
optNoExpandValue = new TokenList(noExpandValue);
1800-
#endif
18011774
}
18021775

18031776
return true;
@@ -2437,47 +2410,9 @@ namespace simplecpp {
24372410

24382411
#ifdef SIMPLECPP_WINDOWS
24392412

2440-
#if __cplusplus >= 201103L
24412413
using MyMutex = std::mutex;
24422414
template<class T>
24432415
using MyLock = std::lock_guard<T>;
2444-
#else
2445-
class MyMutex {
2446-
public:
2447-
MyMutex() {
2448-
InitializeCriticalSection(&m_criticalSection);
2449-
}
2450-
2451-
~MyMutex() {
2452-
DeleteCriticalSection(&m_criticalSection);
2453-
}
2454-
2455-
CRITICAL_SECTION* lock() {
2456-
return &m_criticalSection;
2457-
}
2458-
private:
2459-
CRITICAL_SECTION m_criticalSection;
2460-
};
2461-
2462-
template<typename T>
2463-
class MyLock {
2464-
public:
2465-
explicit MyLock(T& m)
2466-
: m_mutex(m) {
2467-
EnterCriticalSection(m_mutex.lock());
2468-
}
2469-
2470-
~MyLock() {
2471-
LeaveCriticalSection(m_mutex.lock());
2472-
}
2473-
2474-
private:
2475-
MyLock& operator=(const MyLock&);
2476-
MyLock(const MyLock&);
2477-
2478-
T& m_mutex;
2479-
};
2480-
#endif
24812416

24822417
class RealFileNameMap {
24832418
public:
@@ -4099,7 +4034,3 @@ std::string simplecpp::getCppStdString(const std::string &std)
40994034
{
41004035
return getCppStdString(getCppStd(std));
41014036
}
4102-
4103-
#if (__cplusplus < 201103L) && !defined(__APPLE__)
4104-
#undef nullptr
4105-
#endif

simplecpp.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,6 @@
2727
# define SIMPLECPP_LIB
2828
#endif
2929

30-
#if (__cplusplus < 201103L) && !defined(__APPLE__)
31-
#define nullptr NULL
32-
#endif
33-
3430
#if defined(_MSC_VER)
3531
# pragma warning(push)
3632
// suppress warnings about "conversion from 'type1' to 'type2', possible loss of data"
@@ -214,14 +210,10 @@ namespace simplecpp {
214210
/** generates a token list from the given filename parameter */
215211
TokenList(const std::string &filename, std::vector<std::string> &filenames, OutputList *outputList = nullptr);
216212
TokenList(const TokenList &other);
217-
#if __cplusplus >= 201103L
218213
TokenList(TokenList &&other);
219-
#endif
220214
~TokenList();
221215
TokenList &operator=(const TokenList &other);
222-
#if __cplusplus >= 201103L
223216
TokenList &operator=(TokenList &&other);
224-
#endif
225217

226218
void clear();
227219
bool empty() const {
@@ -395,8 +387,4 @@ namespace simplecpp {
395387
# pragma warning(pop)
396388
#endif
397389

398-
#if (__cplusplus < 201103L) && !defined(__APPLE__)
399-
#undef nullptr
400-
#endif
401-
402390
#endif

0 commit comments

Comments
 (0)