I was having a problem in some production code that I minimized to the following test case:
template<typename T>
void intermediate(T t)
{
func(t); // line 4 ("func not declared in this scope")
}
namespace ns {
struct type {};
}
void func(ns::type const & p); // line 11 ("declared here, later")
void foo(ns::type exit_node)
{
intermediate(exit_node); // line 15 ("required from here")
}
GCC 4.5 compiles this fine. Both with and without -std=c++11
, 4.7 and 4.9 produce messages like:
test.cpp: In instantiation of ‘void intermediate(T) [with T = ns::type]’:
test.cpp:15:27: required from here
test.cpp:4:5: error: ‘func’ was not declared in this scope, and no declarations were found by argument-dependent lookup at the point of instantiation [-fpermissive]
test.cpp:11:6: note: ‘void func(const ns::type&)’ declared here, later in the translation unit
All of the following three things will cause the file to successfully compile:
func(ns::type)
into the ns
namespace (allowing ADL to find it in ns
)type
into the global namespace (allowing ADL to find it in ::
)intermediate
and call func
directly from foo
So... what is going on here? Is it legal for GCC to reject this program? Why is func
found by unqualified lookup in the third variant (call func
directly from foo
) but not found by unqualified lookup in the original variant at the point of instantiation?
Each CNAME record associates a service with a domain name, not a physical IP address. The physical IP address is instead identified by your domain's A record. If your IP address changes, you only have to change the A record, not each CNAME record.
CNAME records can be used to alias one name to another. CNAME stands for Canonical Name. A common example is when you have both example.com and www.example.com pointing to the same application and hosted by the same server.
The major advantage of using CNAME is that if we change the IP address of one A record then any CNAME record pointing to that host will also changed. Like if we have a website with highcloud.com then this domain name is hooked up to an A-record which translates the domain name to the appropriate IP address 1.2.
The general rule is that anything that is not in the template definition context can only be picked up via ADL. In other words, normal unqualified lookup is performed only in the template definition context.
Since no declaration of func
is visible when intermediate
was defined, and func
is not in a namespace associated with ns::type
, the code is ill-formed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With