Skip to content

Commit

Permalink
Removed using namespace std; from GenPath
Browse files Browse the repository at this point in the history
The issue:
- rpcndr.h defines `byte` as `typedef unsigned char byte`
- stddef header also defines `std::byte` as `enum class byte : unsigned char {}`
- with `using namespace std`, `byte` can be either `byte` or `std::byte` leading to "error: reference to 'byte' is ambiguous"
- the disambiguation was initially fixed by adding `-std=c++11` as additional C/C++ build parameter
- ...but, GenPath is a mixed C and C++ project so `-std=c++11` got passed as argument to both `gcc` and `g++` leading to "error: invalid argument '-std=c++11' not allowed with 'C'"
Removing `using namespace std;` is the correct way to fix it
  • Loading branch information
negrutiu committed Jun 2, 2024
1 parent 07dfcae commit 2fe6a91
Show file tree
Hide file tree
Showing 10 changed files with 15 additions and 22 deletions.
2 changes: 0 additions & 2 deletions Contrib/VPatch/Source/GenPat/ChunkedFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@
#include "ChunkedFile.h"
#include "tchar.h"

using namespace std;

ChunkedFile::ChunkedFile(bistream& f, TFileOffset fSize, TFileOffset chunkSize) :
chunks(NULL) {

Expand Down
4 changes: 2 additions & 2 deletions Contrib/VPatch/Source/GenPat/FileFormat1.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ namespace FileFormat1 {
return fileCount;
}

void writePatch(bostream& patch, bistream& target, vector<SameBlock*>& sameBlocks, TChecksum* sourceCRC, TChecksum* targetCRC, TFileOffset currentFileCount, POSIX::ALT_FILETIME targetTime) {
void writePatch(bostream& patch, bistream& target, std::vector<SameBlock*>& sameBlocks, TChecksum* sourceCRC, TChecksum* targetCRC, TFileOffset currentFileCount, POSIX::ALT_FILETIME targetTime) {
TFileOffset bodySize = 0;
TFileOffset noBlocks = 0;
TFileOffset noBlocksOffset = patch.tellp();
Expand All @@ -163,7 +163,7 @@ namespace FileFormat1 {
TFileOffset bodySizeOffset = patch.tellp();
writeDword(patch,bodySize);

for(vector<SameBlock*>::iterator iter = sameBlocks.begin(); iter != sameBlocks.end(); iter++) {
for(auto iter = sameBlocks.begin(); iter != sameBlocks.end(); iter++) {
SameBlock* current = *iter;

// store current block
Expand Down
4 changes: 1 addition & 3 deletions Contrib/VPatch/Source/GenPat/FileFormat1.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,9 @@
#include "PatchGenerator.h"
#include "POSIXUtil.h"

using namespace std;

namespace FileFormat1 {
TFileOffset removeExistingPatch(bistream& in, TFileOffset inSize, bostream& out, TChecksum* removeCRC, bool existenceIsError);
void writePatch(bostream& patch, bistream& target, vector<SameBlock*>& sameBlocks, TChecksum* sourceCRC, TChecksum* targetCRC, TFileOffset currentFileCount, POSIX::ALT_FILETIME targetTime);
void writePatch(bostream& patch, bistream& target, std::vector<SameBlock*>& sameBlocks, TChecksum* sourceCRC, TChecksum* targetCRC, TFileOffset currentFileCount, POSIX::ALT_FILETIME targetTime);
}

#endif // FileFormat1_H
5 changes: 4 additions & 1 deletion Contrib/VPatch/Source/GenPat/GlobalTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,10 @@
#include <ios>
#include <string>

using namespace std;
using ios = std::ios;
using ios_base = std::ios_base;
using streamsize = std::streamsize;
using streamoff = std::streamoff;

#ifdef _MSC_VER
typedef unsigned char uint8_t;
Expand Down
2 changes: 0 additions & 2 deletions Contrib/VPatch/Source/GenPat/POSIXUtil.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,6 @@
#include <windows.h>
#endif

using namespace std;

namespace POSIX {

void TimeT_To_FILETIME(time_t t, ALT_FILETIME *pft ) {
Expand Down
2 changes: 0 additions & 2 deletions Contrib/VPatch/Source/GenPat/POSIXUtil.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@
#include <string>
#include "tchar.h"

using namespace std;

namespace POSIX {
typedef struct ALT_FILETIME {
uint32_t dwLowDateTime;
Expand Down
2 changes: 1 addition & 1 deletion Contrib/VPatch/Source/GenPat/PatchGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ PatchGenerator::~PatchGenerator() {
if(targetCData != NULL) delete[] targetCData;
}

void PatchGenerator::execute(vector<SameBlock*>& sameBlocks) {
void PatchGenerator::execute(std::vector<SameBlock*>& sameBlocks) {
ChunkedFile* sourceTree = new ChunkedFile(source,sourceSize,blockSize);

// sameBlocks: this vector will store blocks that have been found to be the same
Expand Down
4 changes: 1 addition & 3 deletions Contrib/VPatch/Source/GenPat/PatchGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@
#include "GlobalTypes.h"
#include "ChunkedFile.h"

using namespace std;

typedef struct SameBlock {
TFileOffset sourceOffset;
TFileOffset targetOffset;
Expand Down Expand Up @@ -68,7 +66,7 @@
~PatchGenerator();

// construct the actual patch
void execute(vector<SameBlock*>& sameBlocks);
void execute(std::vector<SameBlock*>& sameBlocks);
};

#endif // PatchGenerator_H
4 changes: 2 additions & 2 deletions Contrib/VPatch/Source/GenPat/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,13 @@ int _tmain( int argc, TCHAR * argv[] ) {
}

// create sameBlock storage
vector<SameBlock*> sameBlocks;
std::vector<SameBlock*> sameBlocks;
// run the patch generator to find similar blocks
gen->execute(sameBlocks);
// construct the actual patch in FileFormat1
FileFormat1::writePatch(patch,target,sameBlocks,sourceCRC,targetCRC,fileCount,POSIX::getFileTime(targetFileName.c_str()));
// cleanup sameblocks
for(vector<SameBlock*>::iterator iter = sameBlocks.begin(); iter != sameBlocks.end(); iter++) {
for(auto iter = sameBlocks.begin(); iter != sameBlocks.end(); iter++) {
delete *iter;
*iter = NULL;
}
Expand Down
8 changes: 4 additions & 4 deletions Contrib/VPatch/Source/GenPat/tchar.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
#include <sstream>

#ifdef _UNICODE
# define tout wcout
# define terr wcerr
# define tout std::wcout
# define terr std::wcerr
# define __T(x) L ## x
# define _T(x) __T(x)
# define _tmain wmain
Expand All @@ -17,8 +17,8 @@

typedef wchar_t TCHAR;
#else
# define tout cout
# define terr cerr
# define tout std::cout
# define terr std::cerr
# define _T(x) x
# define _tmain main
# ifdef _WIN32
Expand Down

0 comments on commit 2fe6a91

Please sign in to comment.