Skip to content

Commit 06cd050

Browse files
committed
Update to c++11
1 parent a3300df commit 06cd050

File tree

5 files changed

+18
-116
lines changed

5 files changed

+18
-116
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: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
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)
5-
64
include(CheckCXXCompilerFlag)
75

86
if (WIN32)
@@ -72,21 +70,6 @@ add_library(simplecpp_obj OBJECT simplecpp.cpp)
7270
add_executable(simplecpp $<TARGET_OBJECTS:simplecpp_obj> main.cpp)
7371
set_property(TARGET simplecpp PROPERTY CXX_STANDARD 11)
7472

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-
9073
add_executable(testrunner $<TARGET_OBJECTS:simplecpp_obj> test.cpp)
9174
set_property(TARGET testrunner PROPERTY CXX_STANDARD 11)
9275

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: 16 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
#define _WIN32_WINNT 0x0602
1313
#include <windows.h>
1414
#undef ERROR
15-
#else
16-
#include <sys/stat.h>
1715
#endif
1816

1917
#include "simplecpp.h"
@@ -40,33 +38,20 @@
4038
#include <stack>
4139
#include <stdexcept>
4240
#include <string>
43-
#if __cplusplus >= 201103L
4441
#ifdef SIMPLECPP_WINDOWS
4542
#include <mutex>
4643
#endif
4744
#include <unordered_map>
48-
#endif
4945
#include <utility>
5046
#include <vector>
5147

5248
#ifdef _WIN32
5349
#include <direct.h>
5450
#else
51+
#include <sys/stat.h>
5552
#include <unistd.h>
5653
#endif
5754

58-
#if __cplusplus >= 201103L
59-
#define OVERRIDE override
60-
#define EXPLICIT explicit
61-
#else
62-
#define OVERRIDE
63-
#define EXPLICIT
64-
#endif
65-
66-
#if (__cplusplus < 201103L) && !defined(__APPLE__)
67-
#define nullptr NULL
68-
#endif
69-
7055
static bool isHex(const std::string &s)
7156
{
7257
return s.size()>2 && (s.compare(0,2,"0x")==0 || s.compare(0,2,"0X")==0);
@@ -372,22 +357,22 @@ class simplecpp::TokenList::Stream {
372357
class StdIStream : public simplecpp::TokenList::Stream {
373358
public:
374359
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
375-
EXPLICIT StdIStream(std::istream &istr)
360+
explicit StdIStream(std::istream &istr)
376361
: istr(istr) {
377362
assert(istr.good());
378363
init();
379364
}
380365

381-
virtual int get() OVERRIDE {
366+
virtual int get() override {
382367
return istr.get();
383368
}
384-
virtual int peek() OVERRIDE {
369+
virtual int peek() override {
385370
return istr.peek();
386371
}
387-
virtual void unget() OVERRIDE {
372+
virtual void unget() override {
388373
istr.unget();
389374
}
390-
virtual bool good() OVERRIDE {
375+
virtual bool good() override {
391376
return istr.good();
392377
}
393378

@@ -406,20 +391,20 @@ class StdCharBufStream : public simplecpp::TokenList::Stream {
406391
init();
407392
}
408393

409-
virtual int get() OVERRIDE {
394+
virtual int get() override {
410395
if (pos >= size)
411396
return lastStatus = EOF;
412397
return str[pos++];
413398
}
414-
virtual int peek() OVERRIDE {
399+
virtual int peek() override {
415400
if (pos >= size)
416401
return lastStatus = EOF;
417402
return str[pos];
418403
}
419-
virtual void unget() OVERRIDE {
404+
virtual void unget() override {
420405
--pos;
421406
}
422-
virtual bool good() OVERRIDE {
407+
virtual bool good() override {
423408
return lastStatus != EOF;
424409
}
425410

@@ -433,7 +418,7 @@ class StdCharBufStream : public simplecpp::TokenList::Stream {
433418
class FileStream : public simplecpp::TokenList::Stream {
434419
public:
435420
// cppcheck-suppress uninitDerivedMemberVar - we call Stream::init() to initialize the private members
436-
EXPLICIT FileStream(const std::string &filename, std::vector<std::string> &files)
421+
explicit FileStream(const std::string &filename, std::vector<std::string> &files)
437422
: file(fopen(filename.c_str(), "rb"))
438423
, lastCh(0)
439424
, lastStatus(0) {
@@ -444,25 +429,25 @@ class FileStream : public simplecpp::TokenList::Stream {
444429
init();
445430
}
446431

447-
~FileStream() OVERRIDE {
432+
~FileStream() override {
448433
fclose(file);
449434
file = nullptr;
450435
}
451436

452-
virtual int get() OVERRIDE {
437+
virtual int get() override {
453438
lastStatus = lastCh = fgetc(file);
454439
return lastCh;
455440
}
456-
virtual int peek() OVERRIDE{
441+
virtual int peek() override{
457442
// keep lastCh intact
458443
const int ch = fgetc(file);
459444
unget_internal(ch);
460445
return ch;
461446
}
462-
virtual void unget() OVERRIDE {
447+
virtual void unget() override {
463448
unget_internal(lastCh);
464449
}
465-
virtual bool good() OVERRIDE {
450+
virtual bool good() override {
466451
return lastStatus != EOF;
467452
}
468453

@@ -523,12 +508,10 @@ simplecpp::TokenList::TokenList(const TokenList &other) : frontToken(nullptr), b
523508
*this = other;
524509
}
525510

526-
#if __cplusplus >= 201103L
527511
simplecpp::TokenList::TokenList(TokenList &&other) : frontToken(nullptr), backToken(nullptr), files(other.files)
528512
{
529513
*this = std::move(other);
530514
}
531-
#endif
532515

533516
simplecpp::TokenList::~TokenList()
534517
{
@@ -547,7 +530,6 @@ simplecpp::TokenList &simplecpp::TokenList::operator=(const TokenList &other)
547530
return *this;
548531
}
549532

550-
#if __cplusplus >= 201103L
551533
simplecpp::TokenList &simplecpp::TokenList::operator=(TokenList &&other)
552534
{
553535
if (this != &other) {
@@ -561,7 +543,6 @@ simplecpp::TokenList &simplecpp::TokenList::operator=(TokenList &&other)
561543
}
562544
return *this;
563545
}
564-
#endif
565546

566547
void simplecpp::TokenList::clear()
567548
{
@@ -1481,11 +1462,7 @@ unsigned int simplecpp::TokenList::fileIndex(const std::string &filename)
14811462

14821463
namespace simplecpp {
14831464
class Macro;
1484-
#if __cplusplus >= 201103L
14851465
using MacroMap = std::unordered_map<TokenString,Macro>;
1486-
#else
1487-
typedef std::map<TokenString,Macro> MacroMap;
1488-
#endif
14891466

14901467
class Macro {
14911468
public:
@@ -2383,48 +2360,9 @@ namespace simplecpp {
23832360
}
23842361

23852362
#ifdef SIMPLECPP_WINDOWS
2386-
2387-
#if __cplusplus >= 201103L
23882363
using MyMutex = std::mutex;
23892364
template<class T>
23902365
using MyLock = std::lock_guard<T>;
2391-
#else
2392-
class MyMutex {
2393-
public:
2394-
MyMutex() {
2395-
InitializeCriticalSection(&m_criticalSection);
2396-
}
2397-
2398-
~MyMutex() {
2399-
DeleteCriticalSection(&m_criticalSection);
2400-
}
2401-
2402-
CRITICAL_SECTION* lock() {
2403-
return &m_criticalSection;
2404-
}
2405-
private:
2406-
CRITICAL_SECTION m_criticalSection;
2407-
};
2408-
2409-
template<typename T>
2410-
class MyLock {
2411-
public:
2412-
explicit MyLock(T& m)
2413-
: m_mutex(m) {
2414-
EnterCriticalSection(m_mutex.lock());
2415-
}
2416-
2417-
~MyLock() {
2418-
LeaveCriticalSection(m_mutex.lock());
2419-
}
2420-
2421-
private:
2422-
MyLock& operator=(const MyLock&);
2423-
MyLock(const MyLock&);
2424-
2425-
T& m_mutex;
2426-
};
2427-
#endif
24282366

24292367
static bool isAbsolutePath(const std::string &path)
24302368
{
@@ -2433,7 +2371,6 @@ static bool isAbsolutePath(const std::string &path)
24332371
return path.length() > 1U && (path[0] == '/' || path[0] == '\\');
24342372
}
24352373
#else
2436-
24372374
static bool isAbsolutePath(const std::string &path)
24382375
{
24392376
return path.length() > 1U && path[0] == '/';
@@ -3934,7 +3871,3 @@ std::string simplecpp::getCppStdString(const std::string &std)
39343871
{
39353872
return getCppStdString(getCppStd(std));
39363873
}
3937-
3938-
#if (__cplusplus < 201103L) && !defined(__APPLE__)
3939-
#undef nullptr
3940-
#endif

simplecpp.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,6 @@
3434
# include <sys/stat.h>
3535
#endif
3636

37-
#if (__cplusplus < 201103L) && !defined(__APPLE__)
38-
#define nullptr NULL
39-
#endif
40-
4137
#if defined(_MSC_VER)
4238
# pragma warning(push)
4339
// suppress warnings about "conversion from 'type1' to 'type2', possible loss of data"
@@ -222,14 +218,10 @@ namespace simplecpp {
222218
/** generates a token list from the given filename parameter */
223219
TokenList(const std::string &filename, std::vector<std::string> &filenames, OutputList *outputList = nullptr);
224220
TokenList(const TokenList &other);
225-
#if __cplusplus >= 201103L
226221
TokenList(TokenList &&other);
227-
#endif
228222
~TokenList();
229223
TokenList &operator=(const TokenList &other);
230-
#if __cplusplus >= 201103L
231224
TokenList &operator=(TokenList &&other);
232-
#endif
233225

234226
void clear();
235227
bool empty() const {
@@ -493,8 +485,4 @@ namespace simplecpp {
493485
# pragma warning(pop)
494486
#endif
495487

496-
#if (__cplusplus < 201103L) && !defined(__APPLE__)
497-
#undef nullptr
498-
#endif
499-
500488
#endif

0 commit comments

Comments
 (0)