PGI 19.4 : error: last line of file ends without a newline

I am aware of similar post https://forums.developer.nvidia.com/t/warning-last-line-of-file-ends-without-a-newline/131018/1

But with newer PGI versions I am seeing this as an error! Is this default behaviour intended?

$ make
Scanning dependencies of target spdlog
[  3%] Building CXX object CMakeFiles/spdlog.dir/src/spdlog.cpp.o
/gpfs/bbp.cscs.ch/ssd/apps/hpc/jenkins/deploy/compilers/2020-02-01/linux-rhel7-x86_64/gcc-4.8.5/pgi-19.4-hdirysdrvd/linux86-64-llvm/19.4/bin/pgc++  -DSPDLOG_COMPILED_LIB -I/gpfs/bbp.cscs.ch/home/kumbhar/tmp/spdlog/include  -fast -O3 -DNDEBUG   --c++11 -A -o CMakeFiles/spdlog.dir/src/spdlog.cpp.o -c /gpfs/bbp.cscs.ch/home/kumbhar/tmp/spdlog/src/spdlog.cpp
"/gpfs/bbp.cscs.ch/home/kumbhar/tmp/spdlog/include/spdlog/details/synchronous_f
          actory.h", line 24: error: last line of file ends without a newline
  } // namespace spdlog
                       ^

I don’t see this behaviour with any other compiler.

Ok, if I am not mistaken, -A being culprit here. As soon as standard complaint flag is added, PGI treat this as an error.

Most of the projects now set “CMAKE_CXX_STANDARD” under CMake and that’s where this -A is injected. At the moment I don’t know what is solution / workaround for this issue.

I end up with following in our CMake project:

if(CMAKE_CXX_COMPILER_ID MATCHES "PGI")
  set(CMAKE_CXX11_STANDARD_COMPILE_OPTION  --c++11)
  set(CMAKE_CXX14_STANDARD_COMPILE_OPTION  --c++14)
 endif()

Note that “-A” flag comes from : cmake/share/cmake-3.15/Modules/Compiler/PGI-CXX.cmake:

include(Compiler/PGI)
__compiler_pgi(CXX)
string(APPEND CMAKE_CXX_FLAGS_MINSIZEREL_INIT " -DNDEBUG")
string(APPEND CMAKE_CXX_FLAGS_RELEASE_INIT " -DNDEBUG")

if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 12.10)
  set(CMAKE_CXX98_STANDARD_COMPILE_OPTION  -A)
  set(CMAKE_CXX98_EXTENSION_COMPILE_OPTION --gnu_extensions)
  set(CMAKE_CXX98_STANDARD__HAS_FULL_SUPPORT ON)
  if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 13.10)
    set(CMAKE_CXX11_STANDARD_COMPILE_OPTION  --c++11 -A)
    set(CMAKE_CXX11_EXTENSION_COMPILE_OPTION --c++11 --gnu_extensions)
    set(CMAKE_CXX11_STANDARD__HAS_FULL_SUPPORT ON)
    if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 15.7)
      set(CMAKE_CXX14_STANDARD_COMPILE_OPTION  --c++14 -A)
      set(CMAKE_CXX14_EXTENSION_COMPILE_OPTION --c++14 --gnu_extensions)
      set(CMAKE_CXX14_STANDARD__HAS_FULL_SUPPORT ON)
      if(CMAKE_CXX_COMPILER_VERSION VERSION_GREATER_EQUAL 17.1)
        set(CMAKE_CXX17_STANDARD_COMPILE_OPTION  --c++17 -A)
        set(CMAKE_CXX17_EXTENSION_COMPILE_OPTION --c++17 --gnu_extensions)
        set(CMAKE_CXX17_STANDARD__HAS_FULL_SUPPORT ON)
      endif()
    endif()
  endif()
endif()

__compiler_check_default_language_standard(CXX 12.10 98)

Hi PramodK,

Yes, Kitware added the “-A” flag to CMake a few years ago. “-A” says to strictly adhere to the C++ standard, so things that would normally only trigger a warning message will be flagged as errors when using -A. I’ve had issue with this as well.

-Mat

Thanks Matt!

I came across following in some other threads:

Modern compilers like gcc, clang and visual studio add a new line on every include, so it’s not really an issue with those ones.

Just additional feedback:

  • Most of the modern C++ CMake projects have set(CMAKE_CXX_STANDARD XX)


  • clang-format also removes new lines at the end of file (bug report open but no action)

This will cause compilation errors. Instead of looking into details, people typically mark compiler being not supported (I saw two cases : fmt and spdlog which are used quite a lot).

So it would be great if something could be done about this (either in CMake or PGI side).

I’m not sure about the newline issue specifically, but for me, using PGI with a more recent GNU STL (like 9.2.0) typically works around these issues. For example, I encountered “-A” issues when building KOKKOS when using the GNU 4.9.3 STL, that went away when using the GNU 9.2 STL. Though, we’ve also done some things in our headers to help as well, so you might try using PGI 19.10 or 20.1.

-Mat