Skip to content

Commit

Permalink
Enable -Wall, fix build warnings and fix regression (#246)
Browse files Browse the repository at this point in the history
* Refs #19676: enable compilation warnings

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19676: fix regression test: use const value defined within a module in a union

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19676: remove unused parameter warning

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19676: %S is not supported in C++11

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19676: remove comparison warning

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19676: remove warning about variable set but unused

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19676: update IDL parser to fail test if there are build warnings

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19676: disable switch-bool warning

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19676: fix non contemplated enum value

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19676: update submodule DDS Test Types

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19676: update IDL Parser submodule

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19676: apply review suggestions

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

* Refs #19680: apply review suggestion

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>

---------

Signed-off-by: JLBuenoLopez-eProsima <joseluisbueno@eprosima.com>
  • Loading branch information
JLBuenoLopez committed Oct 9, 2023
1 parent a17c6d4 commit 187aafd
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ $if(member.annotationOptional)$eprosima::fastcdr::optional<$endif$$member.typeco
member_destructor(ctx, member) ::= <<$if(member.typecode.forwarded)$delete m_$member.name$;$elseif(ctx.generateTypesC)$$if(member.typecode.isStringType)$free(m_$member.name$);
m_$member.name$ = nullptr;$elseif(member.typecode.isType_f)$$if(member.typecode.contentTypeCode.isStringType)$$member_array_cstring_destructor(ctx=ctx, name=memberName(member.name), loopvar=ctx.newLoopVarName, dims=member.typecode.dimensions)$$endif$$endif$$endif$>>

member_array_cstring_destructor(ctx, name, loopvar, dims) ::= <<$if(rest(dims))$for (uint32_t $loopvar$ = 0; $loopvar$ < $name$.size(); ++$loopvar$)
member_array_cstring_destructor(ctx, name, loopvar, dims) ::= <<$if(rest(dims))$for (size_t $loopvar$ = 0; $loopvar$ < $name$.size(); ++$loopvar$)
{
$member_array_cstring_destructor(ctx=ctx, name=indexName(name=name,loopvar=loopvar), loopvar=ctx.nextLoopVarName, dims=rest(dims))$
}$else$for (char* str : $name$)
Expand Down
55 changes: 40 additions & 15 deletions src/main/java/com/eprosima/fastcdr/idl/templates/TypesSource.stg
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,11 @@ $struct.scopedname$::$struct.name$(
$endif$

{
$if(struct.members)$
$struct.members:{ member | $member_copy(ctx=ctx, member=member)$}; separator="\n"$
$else$
static_cast<void>(x);
$endif$
}

$struct.scopedname$::$struct.name$(
Expand All @@ -150,15 +154,23 @@ $struct.scopedname$::$struct.name$(
$endif$

{
$if(struct.members)$
$struct.members:{ member | $member_move(member=member)$}; separator="\n"$
$else$
static_cast<void>(x);
$endif$
}

$struct.scopedname$& $struct.scopedname$::operator =(
const $struct.name$& x)
{
$if(struct.inheritances)$$struct.inheritances : { inheritance | $inheritance.scopedname$::operator =(x);}; separator="\n"$$endif$

$if(struct.members)$
$struct.members:{ member | $member_copy(ctx=ctx, member=member)$}; separator="\n"$
$else$
static_cast<void>(x);
$endif$

return *this;
}
Expand All @@ -168,7 +180,11 @@ $struct.scopedname$& $struct.scopedname$::operator =(
{
$if(struct.inheritances)$$struct.inheritances : { inheritance | $inheritance.scopedname$::operator =(std::move(x));}; separator="\n"$$endif$

$if(struct.members)$
$struct.members:{ member | $member_move(member=member)$}; separator="\n"$
$else$
static_cast<void>(x);
$endif$

return *this;
}
Expand All @@ -182,7 +198,12 @@ bool $struct.scopedname$::operator ==(
\}
}; separator="\n"$$endif$

return $if(struct.members)$($struct.members:{ member | m_$member.name$ == x.m_$member.name$}; separator=" &&\n "$)$else$true$endif$;
$if(!struct.members)$
static_cast<void>(x);
return true;
$else$
return ($struct.members:{ member | m_$member.name$ == x.m_$member.name$}; separator=" &&\n "$);
$endif$
}

bool $struct.scopedname$::operator !=(
Expand Down Expand Up @@ -467,6 +488,10 @@ void $union.scopedname$::_d(
switch (m__d)
{
$union.members:{ member | $unionmember_discriminator_case(member=member, totallabels=union.totallabels)$}; separator="\n"$
$if(!union.defaultMember)$
default:
break;
$endif$
}

if (!b)
Expand Down Expand Up @@ -942,7 +967,7 @@ $scopedtypename$::$typename$(
, release_(true)
{
value_ = new $typecode.contentTypeCode.cppTypename$[length_];
for (uint32_t i = 0; i < length_; ++i)
for (size_t i = 0; i < length_; ++i)
{
$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$
strncpy(value_[i], $typename$_.value_[i], strlen($typename$_.value_[i]) + 1);
Expand All @@ -961,7 +986,7 @@ $scopedtypename$& $scopedtypename$::operator =(
release_ = true;

value_ = new $typecode.contentTypeCode.cppTypename$[length_];
for (uint32_t i = 0; i < length_; ++i)
for (size_t i = 0; i < length_; ++i)
{
$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$
strncpy(value_[i], $typename$_.value_[i], strlen($typename$_.value_[i]) + 1);
Expand Down Expand Up @@ -996,7 +1021,7 @@ $typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode.conte
}

$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$
for (uint32_t count = 0; count < length_; ++count)
for (size_t count = 0; count < length_; ++count)
{
value_[count] = nullptr;
}
Expand Down Expand Up @@ -1024,7 +1049,7 @@ const $typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode
}

$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$
for (uint32_t count = 0; count < length_; ++count)
for (size_t count = 0; count < length_; ++count)
{
value_[count] = nullptr;
}
Expand All @@ -1042,7 +1067,7 @@ void $scopedtypename$::size(
if(value_ != nullptr && size > length_)
{
$typecode.contentTypeCode.cppTypename$* temp = new $typecode.contentTypeCode.cppTypename$[size];
for (uint32_t i = 0; i < length_; ++i)
for (size_t i = 0; i < length_; ++i)
{
$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$
if (value_[i] != nullptr)
Expand Down Expand Up @@ -1086,7 +1111,7 @@ void $scopedtypename$::length(
if(value_ != nullptr && length > length_)
{
$typecode.contentTypeCode.cppTypename$* temp = new $typecode.contentTypeCode.cppTypename$[length];
for (uint32_t i = 0; i < length_; ++i)
for (size_t i = 0; i < length_; ++i)
{
$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$
if (value_[i] != nullptr)
Expand Down Expand Up @@ -1165,7 +1190,7 @@ $typecode.contentTypeCode.cppTypename$* $scopedtypename$::value(
}

$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$
for (uint32_t count = 0; count < length_; ++count)
for (size_t count = 0; count < length_; ++count)
{
value_[count] = nullptr;
}
Expand Down Expand Up @@ -1198,7 +1223,7 @@ const $typecode.contentTypeCode.cppTypename$$if(ctx.generateTypesC)$$if(typecode
}

$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$
for (uint32_t count = 0; count < length_; ++count)
for (size_t count = 0; count < length_; ++count)
{
value_[count] = nullptr;
}
Expand Down Expand Up @@ -1251,18 +1276,18 @@ void $scopedtypename$::serialize(

if (value_ == nullptr && length_ > 0)
{
uint32_t size = (maximum_ == 0) ? length_ : maximum_;
size_t size = (maximum_ == 0) ? length_ : maximum_;
value_ = new $typecode.contentTypeCode.cppTypename$[size];

$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$
for (uint32_t count = 0; count < length_; ++count)
for (size_t count = 0; count < length_; ++count)
{
value_[count] = nullptr;
}
$else$$endif$$else$$endif$
}

for (uint32_t count = 0; count < length_; ++count)
for (size_t count = 0; count < length_; ++count)
{
scdr << value_[count];
}
Expand All @@ -1286,13 +1311,13 @@ void $scopedtypename$::deserialize(
{
free_memory();

uint32_t size = (maximum_ == 0) ? new_length : maximum_;
size_t size = (maximum_ == 0) ? new_length : maximum_;
value_ = new $typecode.contentTypeCode.cppTypename$[size];
}

length_ = new_length;

for (uint32_t count = 0; count < length_; ++count)
for (size_t count = 0; count < length_; ++count)
{
$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$
{
Expand All @@ -1312,7 +1337,7 @@ void $scopedtypename$::free_memory()
if (release_)
{
$if(ctx.generateTypesC)$$if(typecode.contentTypeCode.isStringType)$
for (uint32_t count = 0; count < length_; ++count)
for (size_t count = 0; count < length_; ++count)
{
free(value_[count]);
value_[count] = nullptr;
Expand Down
14 changes: 14 additions & 0 deletions src/main/java/com/eprosima/fastdds/idl/templates/CMakeLists.stg
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,20 @@ project("generated_code")
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_EXTENSIONS OFF)

$if(test)$
if(NOT MSVC OR NOT MSVC_IDE)
set(CMAKE_CXX_FLAGS
"\${CMAKE_CXX_FLAGS} -Wall -pedantic -Wextra -Wno-unknown-pragmas -Wno-error=deprecated-declarations -Wno-switch-bool")
if(CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -Wno-psabi")
set(CMAKE_SHARED_LINKER_FLAGS "\${CMAKE_SHARED_LINKER_FLAGS} -Wl,--no-undefined")
elseif(CMAKE_CXX_COMPILER_ID MATCHES "Clang")
set(CMAKE_CXX_FLAGS "\${CMAKE_CXX_FLAGS} -Wno-deprecated-builtins")
set(CMAKE_SHARED_LINKER_FLAGS "\${CMAKE_SHARED_LINKER_FLAGS} -Wl")
endif()
endif()
$endif$

# Find requirements
find_package(fastcdr 2 REQUIRED)
find_package(fastrtps 2.12 REQUIRED)
Expand Down
Loading

0 comments on commit 187aafd

Please sign in to comment.