[LLVMbugs] [Bug 24174] New: Use of parameter within template parameter of default argument

bugzilla-daemon at llvm.org bugzilla-daemon at llvm.org
Fri Jul 17 18:52:53 PDT 2015


https://llvm.org/bugs/show_bug.cgi?id=24174

            Bug ID: 24174
           Summary: Use of parameter within template parameter of default
                    argument
           Product: libc++
           Version: 3.7
          Hardware: PC
                OS: Windows XP
            Status: NEW
          Severity: normal
          Priority: P
         Component: All Bugs
          Assignee: unassignedclangbugs at nondot.org
          Reporter: david.godfrey99 at gmail.com
                CC: llvmbugs at cs.uiuc.edu, mclow.lists at gmail.com
    Classification: Unclassified

Clang compiles the following code on trunk:

template<int>
constexpr int variable{};

int main() {
    auto f = [] (auto x, int = variable<x>) {};
    f(0, 0);
}

Even though the default argument is never used the code should still fail since
parameters are not allowed anywhere outside an unevaluated operand in a
function declaration.

When the second argument is used (i.e f(0)) or we replace auto with int we get
an error:

error: non-type template argument is not a constant expression
    auto f = [] (auto x, int = variable<x>) {};
                                        ^
note: in instantiation of default function argument expression for
'operator()<int>' required here
    f(0);
     ^
note: read of non-const variable 'x' is not allowed in a constant expression
    auto f = [] (auto x, int = variable<x>) {};

But this error should read more or less like the following:

error: default argument references parameter 'x'

It seems clang does not perform the same error checking when parameter names
are used as non-type template arguments.

-- 
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20150718/b19d9484/attachment.html>


More information about the llvm-bugs mailing list