Skip to content

Commit

Permalink
Nullify output dim/var on entry to getCoordVar
Browse files Browse the repository at this point in the history
  • Loading branch information
ZedThree committed Feb 23, 2022
1 parent f0307d0 commit b18cc3c
Showing 1 changed file with 3 additions and 10 deletions.
13 changes: 3 additions & 10 deletions cxx4/ncGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1346,6 +1346,9 @@ map<string,NcGroup> NcGroup::getCoordVars(NcGroup::Location location) const {

// Get the NcDim and NcVar object pair for a named coordinate variables.
void NcGroup::getCoordVar(const string& coordVarName, NcDim& ncDim, NcVar& ncVar, NcGroup::Location location) const {
// Nullify existing dim/var in case no coordinate variable found
ncDim = NcDim{};
ncVar = NcVar{};

This comment has been minimized.

Copy link
@bear24rw

bear24rw Feb 24, 2022

I'm getting this error:

/tmp/build/netcdf-cxx4/cxx4/ncGroup.cpp:1350:16: error: expected '(' for function-style cast or type construction
  ncDim = NcDim{};
          ~~~~~^
/tmp/build/netcdf-cxx4/cxx4/ncGroup.cpp:1351:16: error: expected '(' for function-style cast or type construction
  ncVar = NcVar{};
% clang++ --version
Homebrew clang version 13.0.0
Target: x86_64-apple-darwin21.1.0
Thread model: posix
InstalledDir: /usr/local/opt/llvm/bin

This comment has been minimized.

Copy link
@ZedThree

ZedThree Feb 24, 2022

Author Contributor

I can reproduce your error if I compile with -std=c++98. Are you constrained to using pre-C++11?

This comment has been minimized.

Copy link
@bear24rw

bear24rw Feb 24, 2022

No my compiler supports up to c++20, I think the issue is the CMakeLists.txt doesn't specify the minimum requirement (CXX_STANDARD) so its not emitting the -std flag at all and i guess clang is defaulting to c++98?

git clone --depth 1 https://github.com/Unidata/netcdf-cxx4.git
cd netcdf-cxx4
mkdir -p build
cd build
cmake \
    -D"CMAKE_INSTALL_PREFIX=/tmp/build/root"\
    -D"BUILD_SHARED_LIBS=OFF"\
    -D"NCXX_ENABLE_TESTS=OFF"\
    ..
make -j$(nproc) VERBOSE=1

This comment has been minimized.

Copy link
@ZedThree

ZedThree via email Feb 24, 2022

Author Contributor

This comment has been minimized.

Copy link
@bear24rw

bear24rw Feb 24, 2022

I dont seem to have anything in my env that would affect it but I can get it to build by explicitly specifying a higher std:

cmake -D"CMAKE_INSTALL_PREFIX=/tmp/build/root"\
 -D"BUILD_SHARED_LIBS=OFF"\
 -D"NCXX_ENABLE_TESTS=OFF"\
 -D"CMAKE_CXX_STANDARD=20"\
 ..
make -j$(nproc)

This comment has been minimized.

Copy link
@ZedThree

ZedThree Feb 25, 2022

Author Contributor

I've had a colleague confirm that AppleClang defaults to C++98 for some reason

This comment has been minimized.

Copy link
@bear24rw

bear24rw Mar 2, 2022

Interesting! So is there a reason that our CMakeLists.txt doesn't specify the min std version?


// search in current group and parent groups.
multimap<string,NcDim>::iterator itD;
Expand Down Expand Up @@ -1385,14 +1388,4 @@ void NcGroup::getCoordVar(const string& coordVarName, NcDim& ncDim, NcVar& ncVar
if(!ncDim.isNull()) break;
}
}

if(ncDim.isNull()) {
// return null objects as no coordinates variables were obtained.
NcDim dimTmp;
NcVar varTmp;
ncDim=dimTmp;
ncVar=varTmp;
return;
}

}

0 comments on commit b18cc3c

Please sign in to comment.