This is an archive of the discontinued LLVM Phabricator instance.

Fix compiler error in Attributes.cpp
ClosedPublic

Authored by kzhuravl on Apr 12 2017, 9:40 AM.

Details

Summary
Compiling Attributes.cpp ...
../../../Attributes.cpp: In member function 'std::__1::pair<unsigned int, llvm::Optional<unsigned int> > llvm::AttributeSet::getAllocSizeArgs() const':
../../../Attributes.cpp:542:69: error: operands to ?: have different types 'std::__1::pair<unsigned int, llvm::Optional<unsigned int> >' and 'std::__1::pair<int, int>'
   return SetNode ? SetNode->getAllocSizeArgs() : std::make_pair(0, 0);
                                                                     ^
../../../Attributes.cpp:543:1: error: control reaches end of non-void function [-Werror=return-type]
 }
 ^

Diff Detail

Repository
rL LLVM

Event Timeline

kzhuravl created this revision.Apr 12 2017, 9:40 AM
kzhuravl edited the summary of this revision. (Show Details)Apr 12 2017, 9:41 AM
arsenm added a subscriber: arsenm.Apr 12 2017, 9:45 AM
arsenm added inline comments.
lib/IR/Attributes.cpp
542 ↗(On Diff #94984)

Could you just add u suffixes to the 0s instead?

kzhuravl added inline comments.Apr 12 2017, 10:07 AM
lib/IR/Attributes.cpp
542 ↗(On Diff #94984)

I could make it std::make_pair(0U, Optional<unsigned>(0)). If that is preferred?

rnk edited edge metadata.Apr 12 2017, 10:29 AM

Which platform exhibits this error? Also, it's an error, not a warning. The -Wreturn-type warning is a follow-on warning caused by the error in the return statement. Is this a problem with current or past versions libc++?

FWIW, I lifted this make_pair usage from elsewhere, hoping it would be portable:

std::pair<unsigned, Optional<unsigned>>
AttributeSetNode::getAllocSizeArgs() const {
  // ...
  return std::make_pair(0, 0);
}
rnk added inline comments.Apr 12 2017, 10:30 AM
lib/IR/Attributes.cpp
542 ↗(On Diff #94984)

That or std::pair<unsigned, Optional<unsigned>>(0, 0). We don't need make_pair if it can't deduce the types.

kzhuravl updated this revision to Diff 95047.Apr 12 2017, 3:57 PM
kzhuravl retitled this revision from Fix warning in Attributes.cpp to Fix compiler error in Attributes.cpp.

Address review feedback.

In D31981#725043, @rnk wrote:

Which platform exhibits this error? Also, it's an error, not a warning. The -Wreturn-type warning is a follow-on warning caused by the error in the return statement. Is this a problem with current or past versions libc++?

FWIW, I lifted this make_pair usage from elsewhere, hoping it would be portable:

std::pair<unsigned, Optional<unsigned>>
AttributeSetNode::getAllocSizeArgs() const {
  // ...
  return std::make_pair(0, 0);
}

Thanks. g++-4.8.2 with libcxx@r264579 on Ubuntu 14.04 or 16.04.

kzhuravl marked 3 inline comments as done.Apr 12 2017, 3:58 PM
rnk accepted this revision.Apr 12 2017, 4:01 PM

lgtm

This revision is now accepted and ready to land.Apr 12 2017, 4:01 PM
This revision was automatically updated to reflect the committed changes.