Skip to content

Net Exception: Address family not supported with clang #1950

@Bjoe

Description

@Bjoe

I write a simple HTTP client to download a file and I get following exception:

Net Exception: Address family not supported

I try to find out the root cause of these error because my code was working.
I found following weird bug:

I print following member stack addresses:

  • _counter member in RefCountedObject -> poco/Foundation/src/RefCountedObject.cpp:26
  • _addr member in IPv4SocketAddressImpl -> poco/Net/src/SocketAddressImpl.cpp:63
  • _addr member in IPv4SocketAddressImpl addr function -> poco/Net/include/Poco/Net/SocketAddressImpl.h:103

(see also my https://github.com/Bjoe/poco.git Branch: stack_address_issue)

and I get following result:

RefCountedObject::RefCountedObject() Stack address from _counter: 0x2639bc8
IPv4SocketAddressImpl::IPv4SocketAddressImpl() Stack address from _addr: 0x2639bcc
IPv4SocketAddressImpl::addr() Stack address from _addr: 0x2639bc8

WTH... why is the stack address from _addr in function addr the same stack addr in _counter 0x2639bc8 ?

I try some compiler and it looks like it only happens with clang and -std=XXX argument without any optimization:

clang++-3.8 -std=c++11
clang++-4.0 -std=c++11
clang++-3.8 -std=c++14
clang++-4.0 -std=c++14

If I move the function

inline const struct sockaddr* IPv4SocketAddressImpl::addr() const

from the header in the source file it works.

Have somebody an idea?
How looks like on android? They use also clang there.
Is this really a compiler bug?
Looks like on FreeBSD, they use clang as compiler, they have also this issue, see #1684

Here my code to test:

#include <Poco/Net/SocketAddress.h>
int main()
{
  Poco::Net::SocketAddress sa("localhost", 80);
  const sockaddr* s = sa.addr();
  return 0;
}

with my branch:
https://github.com/Bjoe/poco.git Branch: stack_address_issue

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions