dwatteau / scummtr

Fan translation tools for LucasArts SCUMM games
MIT License
24 stars 4 forks source link

[Build] ScummRp/file.hpp compilation error with Clang and GCC #2

Closed dwatteau closed 3 years ago

dwatteau commented 3 years ago

The original source of scummrp (and thus scummtr) currently fails to build on most Unix environments.

g++ gives the best error messages:

/src/ScummRp/file.hpp: In member function 'virtual void SeqFile<T>::open(const char*, BackUp&)':
/src/ScummRp/file.hpp:317:7: error: there are no arguments to 'is_open' that depend on a template parameter, so a declaration of 'is_open' must be available [-fpermissive]
  317 |   if (is_open() != _srcFile.is_open())
      |       ^~~~~~~
/src/ScummRp/file.hpp:317:7: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
/src/ScummRp/file.hpp: In member function 'virtual void SeqFile<T>::close()':
/src/ScummRp/file.hpp:328:8: error: there are no arguments to 'is_open' that depend on a template parameter, so a declaration of 'is_open' must be available [-fpermissive]
  328 |   if (!is_open())
      |        ^~~~~~~
/src/ScummRp/file.hpp:330:18: error: '_size' was not declared in this scope
  330 |   if (_tmpSize < _size)
      |                  ^~~~~
/src/ScummRp/file.hpp:333:5: error: there are no arguments to 'seekp' that depend on a template parameter, so a declaration of 'seekp' must be available [-fpermissive]
  333 |     seekp(_tmpSize, std::ios::beg);
      |     ^~~~~
/src/ScummRp/file.hpp: In member function 'virtual File& SeqFile<T>::read(char*, std::streamsize)':
/src/ScummRp/file.hpp:354:10: error: there are no arguments to 'tellg' that depend on a template parameter, so a declaration of 'tellg' must be available [-fpermissive]
  354 |   gpos = tellg(std::ios::beg);
      |          ^~~~~
/src/ScummRp/file.hpp:355:18: error: '_size' was not declared in this scope
  355 |   if (gpos + n > _size)
      |                  ^~~~~
/src/ScummRp/file.hpp:356:64: error: '_path' was not declared in this scope
  356 |    throw File::UnexpectedEOF(xsprintf("Unexpected EOF in: %s", _path));
...

clang++ doesn't like this either. It's just fatal for it.

Actually, an old g++ 3.3.5 does accept this construct, though. It seems to be an invalid C++ contsruct, that g++ 3.4 and later just completely refuses. Strangely, cl.exe still accepts it without a single warning, even with MSVC 2019 in C++17 mode.

This should help fixing this:

dwatteau commented 3 years ago

Might be solved by e78e3d9a616f7ba173dc85bd1e3123101392916b, at least in part.

Will need to do various checks with different compiler versions.

dwatteau commented 3 years ago

53a326cec9209743522f50f0aaeaa018fa698c33 should also fix the dependent-name 'SeqFile<T>::Error' is parsed as a non-type, but instantiation yields a type compilation error observed (at least) with GCC 4.0 and GCC 4.2.

Closing.