http://llvm.org/bugs/show_bug.cgi?id=5206

           Summary: logical operators should produce bool instead of int in
                    C++
           Product: clang
           Version: trunk
          Platform: All
        OS/Version: All
            Status: ASSIGNED
          Severity: normal
          Priority: P2
         Component: Semantic Analyzer
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected], [email protected]


C++ 5.[14,15]: the && and || operators produce a bool.

C has no bool type and thus the rule is different there:

C99 6.5.[13,14]: the && and || operators produce an int.

Currently clang always thinks the result is an int (the C99 behavior).  It
should consider the result type bool in C++ mode.

Proposed addition to test/SemaCXX/bool.cpp:

// static_assert_arg_is_bool(x) compiles only if x is a bool.
template <typename T>
void static_assert_arg_is_bool(T x) {
  bool* p = &x;
}

void test2() {
  int n = 2;
  static_assert_arg_is_bool(n && 4);
  static_assert_arg_is_bool(n || 5);
}


-- 
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
_______________________________________________
LLVMbugs mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/llvmbugs

Reply via email to